#ISystem depending on an IDataComponent Singleton [Solved]

1 messages · Page 1 of 1 (latest)

wild geyser
#

I have a singleton Entity with an IDataComponent on it. It is being created with a Baker.
I have a system i want to run each update, but in the systems OnCreate method i need to catch that IDataComponent:

var world = SystemAPI.GetSingletonEntity<WorldProperties>();

I need to do that in the OnCreate because i use it to initialize some persistent NativeArrays that i use in the Update method.

If i only needed access to the WorldProperties in the Update method, then i could have used state.RequireForUpdate<WorldProperties>() but since i need access to it already in the OnCreate, this does not work.

Is there a way to delay or late-enable my system so the baked entity exist in the OnCreate?

unkempt ledge
#

Well, no that's not possible however ISystemStartStop is your friend. Starting before OnUpdate is called the first time and ending on the final frame the last time OnUpdate is called.
So in OnCreate you can use require for update. In OnStart you can create the collections and in OnStop you can dispose them.

wild geyser
#

Oh so that means OnStart is only called once, and right before OnUpdate - sounds like excatly what i need? Thanks - i'll try it out 🙂