How to get ComponentData from outside of the ECS system?

In the example I found that the player HUD is also using a ComponentSystem so getting a calculated data is easy with just [Inject].

When changing my own game piece by piece to ECS + Jobs there must be some point I want the data out for use in the old way. For example if I wish to get some data in the ECS system to my UI that updates itself using MonoBehaviour and Update(), what should I do? How can I manually Inject?

The “Hybrid” example goes from MonoBehaviour → ECS but not the other way so everything that uses the data from the thing I tried to convert to ECS must all become ECS, I just want to try it out part by part first

1 Like

You can get EntityManager from current World or You can use static fields in ecs system and get them in mono behaviour.

Thanks, I will try it out. I have one more question though, how to ensure that all of my ECS happens before or after a particular MonoBehaviour?

The order of data usage of my game is currently heavily depending on script execution order, and if I move something in the middle of this order from MonoBehaviour to ComponentSystem I want it to be in the same order if possible. I see [UpdateAfter, but is that only among systems?

If it is a JobComponentSystem I want a way to get its JobHandle and call .Complete. Currently in my understanding, their “JobHandle OnUpdate(inputDeps)” is being run by some unknown code I don’t know about (a system runner?) and that code would be holding the JobHandler, am I right? How to get that?

UpdateBefore UpdateAfter attributes on systems.

Any update on how you approached your UI system?

Right now in the same file that I have my UI’s MonoBehaviour I have an another system class bundled in it. In there of course I can inject the data that is the result of ECS computations that I want. (after ensuring this system runs the last in my chain.)

In this system not only injecting ECS data, I also inject ComponentArray of the thing that is just below in the same file. (Make sure to attach GameObjectEntity so that it shows up in this inject) If I am sure there is only one I can just use [0] on them to select it. Then I call my old methods on them to finally transfer data from ECS world back to mono world.

So, basically all MonoBehaviour needs a complimenting system that has ComponentDataArray + ComponentArray inject in the same system. (Of course needs to be 2 different injects) This is the bridging point. It is not so painful to type after I have my own ECS library built for this purpose (https://github.com/5argon/E7Unity/tree/master/E7ECS - E7ECSReactiveSystem.cs - MonoDataCS<MonoComponent, DataComponent> system template. I subclass from this along with some generic tricks and instantly get the connection to mono world. Look at it if you need some guidance.)

4 Likes