Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ public void SpawnAsPlayerObject(ulong clientId, bool destroyWithScene = false)
/// <param name="destroy">(true) the <see cref="GameObject"/> will be destroyed (false) the <see cref="GameObject"/> will persist after being despawned</param>
public void Despawn(bool destroy = true)
{
MarkVariablesDirty(false);
NetworkManager.SpawnManager.DespawnObject(this, destroy);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,14 @@ public virtual void SetDirty(bool isDirty)
{
m_IsDirty = isDirty;

if (m_NetworkBehaviour == null)
{
Debug.LogWarning($"NetworkVariable is written to, but doesn't know its NetworkBehaviour yet. " +
"Are you modifying a NetworkVariable before the NetworkObject is spawned?");
return;
}

if (m_IsDirty)
{
if (m_NetworkBehaviour == null)
{
Debug.LogWarning($"NetworkVariable is written to, but doesn't know its NetworkBehaviour yet. " +
"Are you modifying a NetworkVariable before the NetworkObject is spawned?");
return;
}
m_NetworkBehaviour.NetworkManager.MarkNetworkObjectDirty(m_NetworkBehaviour.NetworkObject);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ShowHideObject : NetworkBehaviour
{
public static List<ShowHideObject> ClientTargetedNetworkObjects = new List<ShowHideObject>();
public static ulong ClientIdToTarget;
public static bool Silent;

public static NetworkObject GetNetworkObjectById(ulong networkObjectId)
{
Expand Down Expand Up @@ -58,7 +59,10 @@ private void Awake()

public void Changed(int before, int after)
{
Debug.Log($"Value changed from {before} to {after}");
if (!Silent)
{
Debug.Log($"Value changed from {before} to {after}");
}
}
}

Expand Down Expand Up @@ -264,5 +268,29 @@ public IEnumerator NetworkShowHideQuickTest()
yield return CheckVisible(true);
}
}

[UnityTest]
public IEnumerator NetworkHideDespawnTest()
{
m_ClientId0 = m_ClientNetworkManagers[0].LocalClientId;
ShowHideObject.ClientTargetedNetworkObjects.Clear();
ShowHideObject.ClientIdToTarget = m_ClientId0;
ShowHideObject.Silent = true;

var spawnedObject1 = SpawnObject(m_PrefabToSpawn, m_ServerNetworkManager);
var spawnedObject2 = SpawnObject(m_PrefabToSpawn, m_ServerNetworkManager);
var spawnedObject3 = SpawnObject(m_PrefabToSpawn, m_ServerNetworkManager);
m_NetSpawnedObject1 = spawnedObject1.GetComponent<NetworkObject>();
m_NetSpawnedObject2 = spawnedObject2.GetComponent<NetworkObject>();
m_NetSpawnedObject3 = spawnedObject3.GetComponent<NetworkObject>();

m_NetSpawnedObject1.GetComponent<ShowHideObject>().MyNetworkVariable.Value++;
m_NetSpawnedObject1.NetworkHide(m_ClientId0);
m_NetSpawnedObject1.Despawn();

yield return NetcodeIntegrationTestHelpers.WaitForTicks(m_ServerNetworkManager, 5);

LogAssert.NoUnexpectedReceived();
}
}
}