MLAPI Nested Objects or Network Behaviours?

Boss with Nested Objects

My Xevious Boss is an object with five child, or nested, objects. To convert this into an MLAPI object I added a NetworkObject to each node, i.e. one for the root Boss and one each for the nested objects. When I instantiate the boss, or in MLAPI terms Spawn the boss, the root object would have a network Id but all the nested objects would just be set to zero. I have seen this before and I have previously worked-around the problem by making the root act as a relay/proxy for the children. But this time I was determined that each nested object should be responsible for itself and not rely on the parent knowing more than it should.

Network Object or Network Behaviour?

My problem was a fundamental misunderstanding about two important concepts, Network Object and Network Behaviour. When I convert a MonoBehaviour to be, “MLAPI aware” I change it to a NetworkBehaviour. For this to work I thought it requires an attached Network Object. However, when I tried to use the network API, e.g. call a ClientRpc method, it would not work — this was confirmed by asking for the network Id which would be 0.

Turns out my assumption was slightly off. If the parent (root) object has a Network Object then all the nested objects can just be NetworkBehaviours. More than that, the must NOT have Network Objects. As soon as I removed the Network Object component from the children everything started working.

PS. Thanks to _rmrtn on the MLAPI servers for pointing me in the right direction.

Unity, VR, Enterprise and .Net Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Private Route in react-router v6

Creating an e-commerce App with Ignite Bowser with Wordpress Woo-commerce as a backend — Part II

Adding the social media share buttons component to an Angular application

What Programmers Don’t Tell You About Being a Programmer

Deep Linking in React Native

Render conditionally Button or Link in react with typescript and emotion

Async Behavior in Vue Components

Reactivity in Vue.js apps using Vuex

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Paul Marsh

Paul Marsh

Unity, VR, Enterprise and .Net Developer

More from Medium

Galaxy Shooter 2D — LookAt (2D)

2D Homing Missile in Unity

Changing Variable Names in Code in Unity

2.5D Phase1 Framework: Collectible