com.unity.netcode.gameobjects
com.unity.netcode.gameobjects copied to clipboard
Custom NetworkVariable with access to m_NetworkBehaviour
Hello,
I just upgrade MLAPI in develop and I have a bunch of error that need to be fixing. I create custom NetworkVariable so that client can also write. I need to determine that only client that owner of this NetworkVariable that can write. So I need to access m_NetworkBehaviour (before it was named _owner) to check it. But this changes and I cannot access it anymore.
In the code I see
private protected NetworkBehaviour m_NetworkBehaviour;
Therefore I think this m_NetworkBehaviour can only be access from child in the same assembly. Why you restrict the access of this network behaviour? And what are the solution or maybe workaround to access it?
Thanks in advanced.
I am not quite sure why the access is restricted in sub-classes. So take my solution with a grain of salt.
An easy way to get access to the NetworkBehaviour
would be to override the Initialize(NetworkBehaviour)
method and store it for yourself. Don't forget to call base.Initialize
.
+1 for this issue - I can't see why the m_NetworkBehaviour variable would be restricted outside the assembly. I'm trying to make a custom NetworkVariable type by inheriting from NetworkBehaviourBase and should be able to access this field.
I am not quite sure why the access is restricted in sub-classes. So take my solution with a grain of salt.
An easy way to get access to the
NetworkBehaviour
would be to override theInitialize(NetworkBehaviour)
method and store it for yourself. Don't forget to callbase.Initialize
.
If this worked when this was posted, it no longer does. Initialize(NetworkBehaviour)
is not virtual and can't be overridden.
I am not quite sure why the access is restricted in sub-classes. So take my solution with a grain of salt.
An easy way to get access to the
NetworkBehaviour
would be to override theInitialize(NetworkBehaviour)
method and store it for yourself. Don't forget to callbase.Initialize
.If this worked when this was posted, it no longer does.
Initialize(NetworkBehaviour)
is not virtual and can't be overridden.
Yeah, its a bummer. Originally with MLAPI, initialize was override-able.