@@ -212,6 +212,7 @@ internal unsafe void __sendClientRpc(FastBufferWriter writer, uint rpcMethodId,
212
212
213
213
/// <summary>
214
214
/// 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
215
216
/// </summary>
216
217
public NetworkManager NetworkManager => NetworkObject . NetworkManager ;
217
218
@@ -253,8 +254,24 @@ internal unsafe void __sendClientRpc(FastBufferWriter writer, uint rpcMethodId,
253
254
/// </summary>
254
255
public bool IsSpawned => HasNetworkObject ? NetworkObject . IsSpawned : false ;
255
256
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
+
256
266
/// <summary>
257
267
/// 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
+ ///
258
275
/// </summary>
259
276
public NetworkObject NetworkObject
260
277
{
0 commit comments