---
tags:
    - "Audio Source"
    - "Clip"
    - "Sound"
    - "Music"
    - "Component"
    - "Read"
---

# Game Object Audio Resource

[Game Object](index.md) / **Game Object Audio Resource**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

The Audio Resource assigned to the Audio Source component of a Game Object

## Parameters

| Name | Description |
| :--- | :---------- |
| Game Object | The Game Object the Audio Resource is read from |

## Code

```cs
using System;
using UnityEngine;
using UnityEngine.Audio;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Game Object Audio Resource")]
    [Category("Game Object/Game Object Audio Resource")]

    [Description("The Audio Resource assigned to the Audio Source component of a Game Object")]
    [Image(typeof(IconAudioSource), ColorTheme.Type.Yellow, typeof(BadgeCubeSolid))]

    [Parameter("Game Object", "The Game Object the Audio Resource is read from")]

    [Keywords("Audio Source", "Clip", "Sound", "Music", "Component", "Read")]

    [Serializable]
    public class TypeAudioResourceGameObject : TypeAudioResource
    {
        [SerializeField] private GetGameObject m_GameObject = new GetGameObject();

        public override AudioResource Get(Args args)
        {
            GameObject gameObject = this.m_GameObject.Get(args);
            if (gameObject == null) return null;

            return gameObject.TryGetComponent(out AudioSource audioSource) ? audioSource.resource : null;
        }

        public override string ToString()
        {
            return $"{this.m_GameObject} Audio Resource";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
```

