Best way to communicate between ISystem and MonoBehaviour?

Hey everyone,

In my game I use both MonoBehaviour and ISystem.

I wanted to know what’s the best way to speak with ISystem from monobehavior and vice versa?

Is there some sort of an event system that can be sent with values from Mono to ISystem or something similar?

For example, when I want to Instantiate a new entity, I want to tell from Mono to the ISystem to do so and I want to tell the Mono that the Isystem is done.

Obviously that can happens thousands of times in the middle of the game in any moment of the game.

Thanks!

Use a SystemBase as a bridge.

5 Likes

Yes, you have to use SystemBase. Only SystemBase systems can access class instance like MonoBehaviors and GameObjects. A way I personally favor then is using injected dependencies for the system, so the System can access the ECS data and gets the required MonoBehaviors/GameObjects to work with. But this would require proper Dependency Injection and customized system setup process, because ECS does not have any kind of DI integrated. But there a certainly other ways for accessing MonoBehaviors/GameObjects.

2 Likes

Thank you both. That would work for my case.

I turned my monobehavior into singleton, so I am able to call static getinstance from Isystem.
When UI needs to push action into ECS, I use entitymanager to add components from monos

3 Likes