Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Convenience feature: GetSingleton() ref return

Discussion in 'Data Oriented Technology Stack' started by Ramobo, Oct 12, 2019 at 12:29 AM.

  1. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    17
    I say it would in some cases be more convenient than having to do SetSingleton(). e.g.:
    Code (CSharp):
    1. ref SingletonInts singletonInts = ref GetSingleton<SingletonInts>();
    2.  
    3. singletonInts.value1 = 0;
    4. singletonInts.value2 += 1;
    As opposed to:
    Code (CSharp):
    1. SingletonInts singletonInts = GetSingleton<SingletonInts>();
    2.  
    3. SetSingleton(new SingletonInts
    4. {
    5.     value1 = 0
    6.     value2 = singletonInts.value2 + 1
    7. });
    You can't access the ref variable from a lambda expression due to what sounds like an edge case to me, but this is still useful for, say, an input system.
     
    Last edited: Oct 12, 2019 at 1:53 AM