---
tags:
    - "Sprite Renderer"
    - "Image"
    - "UI"
    - "Texture"
    - "Component"
    - "Read"
---

# Game Object Sprite

[Game Object](index.md) / **Game Object Sprite**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

The Sprite used by the Sprite Renderer or the Image component of a Game Object

## Parameters

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

## Code

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

namespace VisualScript.Runtime
{
    [Get]

    [Title("Game Object Sprite")]
    [Category("Game Object/Game Object Sprite")]

    [Description("The Sprite used by the Sprite Renderer or the Image component of a Game Object")]
    [Image(typeof(IconSprite), ColorTheme.Type.Purple, typeof(BadgeCubeOutline))]

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

    [Keywords("Sprite Renderer", "Image", "UI", "Texture", "Component", "Read")]

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

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

            if (gameObject.TryGetComponent(out SpriteRenderer spriteRenderer)) return spriteRenderer.sprite;
            if (gameObject.TryGetComponent(out Image image)) return image.sprite;

            return null;
        }

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

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

```

