hello im having a weird issue with despawning objects. i currently only would like to have a player object on the local player (i dont think i even need it on the server either but i believe it needs to exist on the server anyways) when i call Despawn(destroy: false); as well as setting the donwdestroywithowner bool as true i have varified the flag on the local player as correct however when a new client connects and calls the rpc to despawn it it happens on the local player as well(server objects persist)
heres the code block that handles creation
private void SignInSuccessful()
{
NetworkManager myNetworkManager = NetworkManager.Singleton;
myNetworkManager.NetworkConfig.ConnectionApproval = true;
if (userName == "test")
{
myNetworkManager.ConnectionApprovalCallback += ApproveConnection;
myNetworkManager.OnClientConnectedCallback += newClientConnected;
myNetworkManager.StartServer();
}
else
{
myNetworkManager.StartClient();
StartCoroutine(setPlayerData());
}
//Debug.Log(userName + " has signed in with Id " + AuthenticationService.Instance.PlayerId + " services profile = " + AuthenticationService.Instance.Profile + " local client id " + myNetworkManager.LocalClientId);
}
heres the coroutein
private IEnumerator setPlayerData()
{
while (MyPlayerController.LocalInstance == null)
{
//Debug.Log("player object not found");
yield return null;
}
int networkID = (int)MyPlayerController.LocalInstance.getNetworkClientIdFromLocalPlayer();
string myPlayerID = AuthenticationService.Instance.PlayerId;
myPlayerIdentificationData = new(networkID, userName, myPlayerID);
Debug.Log("authman has set the player data as networkId:" + myPlayerIdentificationData.NetworkClientID + " userName:" + myPlayerIdentificationData.PlayerName + " playerId:" + myPlayerIdentificationData.PlayerID);
MyPlayerController.LocalInstance.updatePlayerDataStateOnServerRPC();
}
when the player is spawned here is the player controller that handles the despawn
public override void OnNetworkSpawn()
{
NetworkObject myNetworkObject = this.NetworkObject;
//Debug.Log("is local player:" + IsLocalPlayer + " is owner:" + IsOwner);
if (IsLocalPlayer)
{
myNetworkObject.DontDestroyWithOwner = true;
LocalInstance = this;
StartCoroutine(WaitForPlayerData());
}
else
{
if(!IsServer)
{
DestroyIfObjectIsNotLocalPlayerOnServerRPC();
}
}
}
and finally the rpc
[ServerRpc (RequireOwnership = false)] private void DestroyIfObjectIsNotLocalPlayerOnServerRPC()
{
this.NetworkObject.Despawn(destroy: false);
}
been struggling with this all weekend can anyone provide some more insight into my issue? thanks for looking!