@@ -212,6 +212,7 @@ internal unsafe void __sendClientRpc(FastBufferWriter writer, uint rpcMethodId,
212212
213213 /// <summary>
214214 /// Gets the NetworkManager that owns this NetworkBehaviour instance
215+ /// See note around `NetworkObject` for how there is a chicken / egg problem when we are not initialized
215216 /// </summary>
216217 public NetworkManager NetworkManager => NetworkObject . NetworkManager ;
217218
@@ -253,8 +254,24 @@ internal unsafe void __sendClientRpc(FastBufferWriter writer, uint rpcMethodId,
253254 /// </summary>
254255 public bool IsSpawned => HasNetworkObject ? NetworkObject . IsSpawned : false ;
255256
257+ internal bool IsBehaviourEditable ( )
258+ {
259+ // Only server can MODIFY. So allow modification if network is either not running or we are server
260+ return ! m_NetworkObject ||
261+ ( m_NetworkObject . NetworkManager == null ||
262+ ! m_NetworkObject . NetworkManager . IsListening ||
263+ m_NetworkObject . NetworkManager . IsServer ) ;
264+ }
265+
256266 /// <summary>
257267 /// Gets the NetworkObject that owns this NetworkBehaviour instance
268+ /// TODO: this needs an overhaul. It's expensive, it's ja little naive in how it looks for networkObject in
269+ /// its parent and worst, it creates a puzzle if you are a NetworkBehaviour wanting to see if you're live or not
270+ /// (e.g. editor code). All you want to do is find out if NetworkManager is null, but to do that you
271+ /// need NetworkObject, but if you try and grab NetworkObject and NetworkManager isn't up you'll get
272+ /// the warning below. This is why IsBehaviourEditable had to be created. Matt was going to re-do
273+ /// how NetworkObject works but it was close to the release and too risky to change
274+ ///
258275 /// </summary>
259276 public NetworkObject NetworkObject
260277 {
0 commit comments