Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Trying to get/set Sprite2D off a tiny component

Discussion in 'Project Tiny' started by furroy, Jun 5, 2019.

  1. furroy

    furroy

    Joined:
    Feb 24, 2017
    Posts:
    93
    Option A: If I set the member to Sprite2D, it expands out the struct in the editor, and I can't just drag and drop a an image from an atlas on to it. If instead I define the sprites like Option B, I can drag the image from the atlas, But then in the code I have an Entity and I can't figure out how to convert the Entity back to Sprite2D to do anything with it.

    Code (CSharp):
    1. // option A
    2.         public Sprite2D leftSprite, rightSprite, frontSprite, backSprite;
    3.  
    4. // option B
    5.         [EntityWithComponents(new[] { typeof(Sprite2D) })]
    6.         public Entity leftSprite, rightSprite, frontSprite, backSprite;
    7.  
     
  2. AlexMasse

    AlexMasse

    Joined:
    Jun 29, 2014
    Posts:
    19
    Sprite2DRenderer.sprite is an Entity field so you can use option B and assign your sprite entities to it directly.
     
  3. robertg_unity

    robertg_unity

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    32
    Sprite2D
    is a component, it is expected to expand as a struct in the inspector. You have to use option B as @Gnome suggested. The
    new[]
    is not necessary thought:
    Code (CSharp):
    1. [EntityWithComponents(typeof(Sprite2D))]
    2. public Entity mySprite;
     
  4. furroy

    furroy

    Joined:
    Feb 24, 2017
    Posts:
    93
    ah thanks for the tip. i had just copy/pasted that from the Sprite2DRenderer struct in Core2D.