Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Setting a sprite to a Sprite2DRenderer

Discussion in 'Project Tiny' started by sniffle63, Jun 22, 2019.

  1. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    Im having a discussion about this in another post, but i figured i should make a new topic because i tried making a new project in it with nothing but spawning an entity threw the entity manager, which works fine, but im un-able to assign a sprite to the Sprite2DRenderer

    I made a short video showing everything i did



    SpawnEntitySystem
    https://pastebin.com/pk9gtdeA

    SpawnConfig
    https://pastebin.com/mwEFaSkM

    Not sure if im doing something wrong, or if its a bug
     
  2. Dunk86

    Dunk86

    Joined:
    May 10, 2015
    Posts:
    53
    My current theory on this is that this a bug using Tiny with 2019.3.0a5.
    Maybe try with 2019.2.0b4 and see if this blank project gives the same result (as your logic looks fine to me)
     
  3. Frickinlaser

    Frickinlaser

    Joined:
    Jan 19, 2014
    Posts:
    22
    I'm having the same issue with 2019.2.0b6. It seams though that this workflow is not intended. @robertg_unity mentioned it in this post: https://forum.unity.com/threads/get-data-from-config.690772/#post-4635799

     
  4. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    He was meaning if you were storing a reference to an existing scene inside of a config component i believe

    Ill try using a different version and see if it works
     
  5. Reborn1214

    Reborn1214

    Joined:
    Jan 19, 2019
    Posts:
    15
    I have the same question.Using a Entity field in the configuration is not allowed.When I want a Entity field(like Text2DStyleBitmapFont ).I have to create a new entity to store them. config.PNG It's work,But I don't know if that's right.
    Code (CSharp):
    1. var configEntity = World.TinyEnvironment().GetEntityByName( "GameConfig" );
    2. var bitmap =
    3. EntityManager.GetComponentData<Text2DStyleBitmapFont>( configEntity );
    4. var  textEntity = EntityManager.CreateEntity( ArchetypeFactory.TextArchetype );
    5. EntityManager.SetComponentData( textEntity , bitmap );
    6. EntityManager.SetBufferFromString<TextString>( textEntity , " ");
     
  6. Frickinlaser

    Frickinlaser

    Joined:
    Jan 19, 2014
    Posts:
    22
    He clarified in the same thread that scene references are ok but entities are not. https://forum.unity.com/threads/get-data-from-config.690772/#post-4639591

    My workaround now is to have a component with the sprite references on an entity in the scene. Then a system that copies that data over to a config component with the same properties. Then the system removes the entity since its data are now stored elsewhere. After that the sprites are available in the config data instead. It works but feels ugly.
     
  7. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    Yes but hes referring to an entity that exist in a scene, none of my code is linking a config file to an existing Entity. My config file only holds a sprite graphic
     
  8. Frickinlaser

    Frickinlaser

    Joined:
    Jan 19, 2014
    Posts:
    22
    Your config component refers to an Entity that has a Sprite2D component. And if I understand it correctly, the Entity containing the config component exists in its own scene, and entity references across scenes are not supported.
    I could be getting this wrong, but that's how I interpret it. When trying myself, the Entity reference in the config Component is null.
     
  9. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    My config component only has a link to a sprite graphic which does not exist within the inspector, only my project files. So its not a cross scene reference, its just a link to a file in my project.

    What hes saying in his post is you cant link an Entity from a scene in your inspector to a component in your configuration's. Which is understandable

    But thats irrelevant because i could put the component on another entity within the same scene and get the same results as the video shows, it would just be more code.