Skip to content

Commit b36d31a

Browse files
fix: networkvariable editor issue (#1293)
1 parent 4bb6d3a commit b36d31a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

com.unity.netcode.gameobjects/Editor/NetworkBehaviourEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private void RenderNetworkVariableValueType<T>(int index) where T : unmanaged
9191
var behaviour = (NetworkBehaviour)target;
9292

9393
// Only server can MODIFY. So allow modification if network is either not running or we are server
94-
if (behaviour.NetworkManager == null || !behaviour.NetworkManager.IsListening || behaviour.NetworkManager.IsServer)
94+
if (behaviour.IsBehaviourEditable())
9595
{
9696
if (type == typeof(int))
9797
{

com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)