#Using SystemAPI in static class?

1 messages · Page 1 of 1 (latest)

west comet
#

Hello, I have this method with a NativeArray return value which I will likely be using in many different systems.
Instead of having to copy-paste this method, am I able to put this method into a static class?

public NativeArray<TowerPartData> GetParts()
{
    BlobArray<E> Es = SystemAPI.GetSingleton<E>().Es.E.Value.Es;
    NativeArray<E> x = new(Es.Length, Allocator.TempJob);

    for (int i = 0; i < towerPartsManaged.Length; i++) 
        x[i] = Es[i];

    return x;
}```
A compromise I can think of is having to pass in my singleton query as an argument, however I'd like to know if I'm able to use the SystemAPI in a static class (perhaps it works because it is being called from a system?)
proven meadow
#

SystemApi depends on being able to write the state to system so you can't have static methods

#

Otherwise it couldn't read the cached state

#

Like system api get singleton is really just, create query in on create, store in system

#

Call query.getsingleton where you used system api

#

It couldn't access the query stored in the system instance if it was static

west comet
#

Ah kk, thanks. There should be a way to pass in a system state to use some sort of external api, would allow for things like these.