Search Issue Tracker

Fixed

Fixed in netcode-gameobjects-2.4.3

Votes

0

Found in [Package]

netcode-gameobjects-2.4.0

netcode-gameobjects-2.4.1

netcode-gameobjects-2.4.2

Issue ID

MTTB-1395

Regression

Yes

DontDestroyWithOwner v2.4.0-v2.4.2 Regression

Package: Multiplayer Netcode for GameObjects

-

Reported within the Netcode for GameObjects forum.

Steps to reproduce:

  • Make sure you are using Unity 6.0 or Unity 6.1 with NGO v2.4.2 installed.

* Install the Multiplayer Play Mode (MPPM) package for ease of testing.
In an opened scene:
** Add a 3D sphere and name it "Ball".
** Add the Rigidbody, NetworkObject, NetworkTransform, and NetworkRigidbody components to the Ball.
** Drag the Ball GameObject in the scene into the prefabs folder to create the network prefab. Delete the Ball GameObject in the scene.
** Add an empty GameObject and name it "Player"
** Add a NetworkObject and the BallSpawner components to the Player.
** Drag the Player GameObject in the scene into the prefabs folder to create the network prefab.
* Delete the Player GameObject in the scene.
** Select the Player prefab
* In the inspector view, assign the Ball prefab to the BallSpawner.BallPrefab property.
** Add an empty GameObject and name it NetworkManager
** Add the NetworkManager component to this.
* In the inspector view, assign the player prefab created to the player prefab property in the NetworkManager.

  • Save the scene and add it to the scenes in build list.
  • Open one virtual client using MPPM.
  • Enter play mode.
  • Enabled the Hierarchy and Inspector view within the virtual client.
  • In the editor and virtual client hierarchy views:

** Select the NetworkManager object and in the NetworkManager's inspector view click the Start Host button.
* Select the NetworkManager object and in the NetworkManager's inspector view click the Start Client button.
Verify the virtual client is connected by selecting the play mode view to bring it into focus and hit the space bar a few times.
** You should see several balls spawn.
* You can verify the spawned balls are owned by the client by selecting one in the inspector view (virtual client) and looking at the Ball's NetworkObject.ClientOwnerId.
* Select the virtual client's NetworkManager and in the inspector view click the disconnect button so the client disconnects.

Actual results: 

The spawned objects with the DontDestroyWithOwner set to their default value of false remain spawned.

Expected results: 

Spawned objects with the DontDestroyWithOwner set to their default value of false should be despawned and destroyed when the owning client disconnects.

Reproducible with versions: 

v2.4.0-v2.4.2

Not reproducible with versions: 

versions earlier than v2.4.0

Tested on (OS): 
Windows

BallSpawner Script:*
{code:c#}
using Unity.Netcode;
using UnityEngine;

public class BallSpawner : NetworkBehaviour
{
public GameObject BallPrefab;
private void Update()
{
if (!IsSpawned || !IsLocalPlayer || (NetworkManager && NetworkManager.ShutdownInProgress))
{
return;
}

if (Input.GetKeyDown(KeyCode.Space) && BallPrefab)
{
if (NetworkManager.DistributedAuthorityMode || IsServer)
{
SpawnBall();
}
else
{
SpawnBallRpc();
}
}
}

private void SpawnBall()
{
var spawnPoint = transform.position + transform.forward * 2.5f;
var instance = NetworkObject.InstantiateAndSpawn(BallPrefab, NetworkManager, OwnerClientId, position: spawnPoint);
var rigidBody = instance.GetComponent<Rigidbody>();
rigidBody.AddForce(transform.forward * 10.0f, ForceMode.Impulse);
}

[Rpc(SendTo.Server)]
private void SpawnBallRpc()
{
SpawnBall();
}
}
{code}

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.