8
\$\begingroup\$

Is it possible to use Hybrid ECS with some components and the standard MonoBehaviour with all your old code?

I want to know because I already have some game mechanics build with the "old" way and I want to build the new ones using hybrid

\$\endgroup\$
8
\$\begingroup\$

It is perfectly possible to mix both styles. The same GameObject can have some of its functionality implemented with the new ECS system and other functionality in classic MonoBehaviour events.

What Unity recommends in their ECS tutorial is in fact to start with a project which uses the old style and then look for features which you think would benefit from refactoring them to the new ECS pattern:

What does this mean for my game?

you can one by one, convert behavior from MonoBehaviour.Update methods into ComponentSystems. You can in fact keep all your data in a MonoBehaviour, and this is in fact a very simple way of starting the transition to ECS style code.

So your scene data remains in GameObjects & components. You continue to use GameObject.Instantiate to create instances etc.

You simply move the contents of your MonoBehaviour.Update into a ComponentSystem.OnUpdate method. The data is kept in the same MonoBehaviour or other components.

This of course does not make use of the benefits of the new Jobs system and the instantiating of entities through an EntityManager. But those new features can also be mixed and matched with classic MonoBehaviours.

For more information about how to convert a game from using the classic MonoBehaviour pattern to the ECS pattern I also recommend this series of videos from the official Unity channel where they convert the good old space shooter example to the new style step-by-step making use of more and more of the new features. Each step in between works perfectly. The final version still uses some classic game objects, because of a feature which is not yet available with the ECS system (particle effects).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.