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

Question tiny time example help

Discussion in 'Project Tiny' started by RoughSpaghetti3211, Feb 5, 2021.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    hello,

    Im playing with the tiny time example and trying to stop the text display, but every time i add a Disabled component it errors, is this not supported or am i way off on how to do this.
    Code (CSharp):
    1.  
    2. TimeEntity = World.GetExistingSystem<ProcessUIEvents>().GetEntityByUIName("TimeText");(edited)
    3. EntityManager.AddComponentData(TimeEntity, new Disabled());
    4.  
     
  2. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    Use RectTransform.Hidden = True to hide any UI element
    Get the rect transform from the entity, set the hidden flag to true then set the component back to the entity
     
  3. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    Let me give that a try, thank you
     
  4. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    That worked thank you, one more question, how do I disable the rendering of a sprite? I tried adding a
    DisableRendering but that doesn't seem to work
     
  5. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    To hide SpriteRenderers, add the
    Disabled
    component to the Entity with the
    SpriteRenderer
    component.

    Code (CSharp):
    1. protected override void OnUpdate()
    2. {
    3.     var input = World.GetExistingSystem<InputSystem>();
    4.  
    5.     if (input.GetKeyDown(KeyCode.H))
    6.     {
    7.         Entities
    8.             .ForEach((Entity e, in SpriteRenderer renderer) =>
    9.             {
    10.                 EntityManager.AddComponent<Disabled>(e);
    11.             })
    12.             .WithStructuralChanges()
    13.             .Run();
    14.     }
    15.     else if (input.GetKeyDown(KeyCode.S))
    16.     {
    17.         Entities
    18.             .WithEntityQueryOptions(EntityQueryOptions.IncludeDisabled)
    19.             .ForEach((Entity e, in SpriteRenderer renderer) =>
    20.             {
    21.                 EntityManager.RemoveComponent<Disabled>(e);
    22.             })
    23.             .WithStructuralChanges()
    24.             .Run();
    25.     }
    26. }
    Note that you need to add
    .WithEntityQueryOptions(EntityQueryOptions.IncludeDisabled)
    to your foreach-queries to find the disabled entities.
     
    RoughSpaghetti3211 and V_i_T like this.
  6. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    Super helpful, thanks Ted
     
    Ted_Wikman likes this.