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. The 2023.1 beta is now available for testing. To find out what's new, have a look at our 2023.1 feature highlights.
    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,688
    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,688
    Let me give that a try, thank you
     
  4. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,688
    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:
    830
    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,688
    Super helpful, thanks Ted
     
    Ted_Wikman likes this.