First off, let me say I successfully have employed this on an old monobehavior game with DOTS/ECS expansion levels. I update the player controller once and it affects both the old levels and the new levels. Now lets get to business.
If you want to use DOTS/ECS, you’ll have to entirely learn a new system. It’s not trivial to learn DOTS, you gotta be smart and have patience. This does not mean you have to make a new game from scratch though like they tell you. I have I have the secret to extend your monobehavior game into a DOTS/ECS game and still reap all the performance.
Before we get into this mono->DOTS ECS conversion kit, let me start by showing you a pitfall so you know I am not unaware of at least one.
1: If you’re not using .foreach in your scripts, you’re not updating your entities properly. You cannot really use your enemies/weapons/etc directly with DOTS/ECS. They must be recoded because there are many of them.
You can however keep your PlayerController since there is only one of them. While Dots/ECS unlocks many cores to deal with multitudes of enemies/explosions/scripts, you still have the original main core to do a few instructions on it without slowldown. A PlayerController is fine to be monobehavior for this reason.
You want two copies of the player in memory. One is the monobehavior GameObject/Mesh the other is an exact duplicate Entity/Mesh.
When you're in monobehavior levels, make the entity renderInvisible/disabled/nocollision.
When you're in Entity mode, you keep the monobehavior GameObject/Mesh: renderInvisible/enabled/nocollision
Also when you're in Entity mode: You make the Entity Visible/enabled/collision.
The way this works and why you can edit your monobehavior only once is:
In gameobject mode it already worked for you.
In Entity Mode: You still operate on the monobehavior gameobject/mesh, but at the end of the update, force map the position/velocity/rotation/etc to the entity.
Boom, you now have your gameobject PlayerController you spent so long on and your game you spent so long on ready to take on some ECS/DOTS custom made enemies and such. It’s a lot of work to make DOTS/ECS scripts for enemies/weapons/etc, but your player literally doesn’t have to be changed much at all.
There’s a huge caveat when it comes to collisions, where you need to sort of handle them gingerly in a few different ways. One of which is not forcing position/velocity overlaps while you’re suffering the effects of a recent collision. There’s other ways to do it too.
I cover more about this these videos:
&
I want more people to dive into Unity ECS/DOTS.
Thanks to the Unity devs for making parallel processing in UNITY a core feature.
If the Unity devs did not make this, I was going to make parallel processing at least in scripts. If any of you wanted to know how to multithread in environments outside of Unity, check out my safe way of doing it here: https://www.starfightergeneral.com/2023/05/how-to-do-multhreaded-coding-correctly/ (I post this because at Carnegie Mellon they did not teach us this. They said threads are the future but said they are too difficult and not worth getting into. This is something I had to find out on my own. CMU was right on both accounts, since in the 90s we only had 1-2 cores, and also multithreaded is tough, but it’s getting manageable if you follow guidelines now).
Thanks also to Unity Discord and this forum and Official Unity forums. There’s still a lot of nice people helping by which I would have never learned DOTS ECS.
Again, this is for real, my own game uses this implementation of one player controller for Monobehavior stages and the same player controller for DOTS/ECS new levels! It’s not feasible to edit two controllers for the player non stop, but it is feasible to make new enemies/stages in DOTS/ECS.
I’m fairly certain a majority of the people who use Unity were unaware that YES, YOU CAN TAKE YOUR OLD GAMES and make new levels into ECS DOTS! You’ll need new scripts for enemies/stages/weapons, but the player controller and all your assets are intact. I hope this super encourages many people to dive into DOTS/ECS. Let me know if this worked on your existing IP.
,Jim