Search Unity

Managed Singletons

Discussion in 'Entity Component System' started by illinar, Jan 16, 2020.

  1. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    Is there a reason for not having managed singleton API? Or are managed components just a new addition not fully supported yet?
     
  2. Flipps

    Flipps

    Joined:
    Jul 30, 2019
    Posts:
    51
    You can use GetSingletonEntity of a managed component class to get the entity and then get the component with GetComponentData.

    But GetSingleton directly is only available for structs.
     
    nous likes this.
  3. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    Yes, thank you. I'm aware of that, but I'm wondering if that is just a temporary limitation or if there is a good reason to not have managed singleton API.
     
  4. Flipps

    Flipps

    Joined:
    Jul 30, 2019
    Posts:
    51
    Yes would be really nice to have these functions

    Code (CSharp):
    1.    
    2. public T GetSingleton<T>() where T : struct, IComponentData;
    3. public bool HasSingleton<T>() where T : struct, IComponentData;
    4. public void SetSingleton<T>(T value) where T : struct, IComponentData;

    no restricted to structs only.

    These functions are working already:


    Code (CSharp):
    1.        
    2. public Entity GetSingletonEntity<T>();
    3. public void RequireSingletonForUpdate<T>();
     
    Enderlook and illinar like this.
  5. ComradeVanti

    ComradeVanti

    Joined:
    May 22, 2015
    Posts:
    25
    In 1.0.0 pre.65 SystemAPI.GetSingletonEntity does not seem to work with managed components
     
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    Because
    SystemAPI
    has inner
    ManagedAPI
    for that.
    Code (CSharp):
    1. SystemAPI.ManagedAPI.GetSingletonEntity