MLAPI and inactive objects

Paul Marsh
2 min readJun 7, 2021

--

Today I was slapped in the face by MLAPI.

I have been happily testing Xevious using each individual level since essentially the levels contain the different types of enemies I need to make “network-ware”. However when I tried a complete run-through of the game it did NOT work.

Levels & the hierarchy

I have currently set up Xevious to use a level mechanism where all the levels are in the hierarchy, but only one is active. What I did not appreciate is that MLAPI makes optimisations based upon if the objects are active or not.

Inactive in the hierarchy, and not spawned

Therefore whilst my current level objects are all active and have synced Network Objects, my next level objects are not even Spawned.

Spawn objects when loading the level

Okay, that means I have to do a little extra work to ensure the objects are spawned. Sure enough the objects now spawned BUT….they are now out of sync. Or rather they do not share the same network Id. I confess this confuses me. But, ever onward…

Current Workaround

Whilst I await a chat with the MLAPI gurus, my, “I am not proud of this” workaround is to start with the game with the hierarchies active and then disable them. This means that when the scene loads MLAPI sets up the correct Network Objects and then Unity disables them.

Active and Spawned

This seems to be enough to get around the problem. Hopefully I will soon have a better solution. One possible solution is to prefab off the levels and instantiate them when needed. This means I still get the visual level designer aspect but, in theory, MLAPI will have a better understanding of what is happening and create the correctly synced objects.

--

--