Closed sk3p71c closed 2 years ago
I can't reproduce this with the provided steps & code (the box is successfully spawned, the OnTriggerEnter code successfully executes, the object is destroyed and removed from the scene, but no console output is observed).
Can you please provide a minimal sample project that reproduces this error?
Thanks Jesse. Example project attached below. I stripped out everything except the scripts I mentioned above. StartHost is now called in the spawning script. If you load the demo scene, you should see a cube fall and hit a spawned sphere, triggering the call to destroy and the issue.
Cheers, Carl
Here are some screenshots of what I see. Before collision:
After collision:
I'm not able to repro with your sample on macOS and Unity 2019.4.19f1, 2020.2.7f1, or 2020.3.1f1. I'll mark this for triage again and we can get it scheduled for someone to look at with a Windows 10 machine in case that's somehow related.
Thanks Jesse. I just tried again with 2020.3.1f1 and still see the issue, so looks like it isn't the Unity version but it could be Windows-related.
Noel is going to try and repo this on Windows
Hi Skep71c,
I have replicated this warning message on my side. This is was a known issue and there is currently a temporary fix to prevent this message from being displayed in our development branch. If you wanted to implement this fix locally you could replace the NetworkObject.OnDestroy method with this:
private void OnDestroy()
{
if (NetworkManager.Singleton != null && NetworkSpawnManager.SpawnedObjects.ContainsKey(NetworkObjectId))
{
NetworkSpawnManager.OnDestroyObject(NetworkObjectId, false);
}
}
Great, thanks for letting me know Noel.
Yeah, it is annoying... that issue should go away come V1.0.0, adding that change to the OnDestroy method should make the spam stop for you.
@will-mearns This was a duplicate bug and is being tracked in MTT-556. (An immediate fix is in place currently but will be further reviewed during our scene object spawning work)
Awesome, thanks for updating the info/links
Hi @sk3p71c, I have upgraded your sample project to work with the new Netcode for GameObjects:
I had to make an adjustment in your scripts to replace the using MLAPI namespace with using Unity.Netcode, and the Spawner.cs:
using Unity.Netcode;
public class Spawner : NetworkBehaviour
{
public NetworkObject target;
void Start()
{
NetworkManager.Singleton.StartHost();
}
public override void OnNetworkDespawn()
{
if (IsServer)
{
var o = Instantiate(target, this.transform.position, this.transform.rotation);
o.Spawn();
}
base.OnNetworkDespawn();
}
}
Running your sample yields no warning messages and the cube spawns and falls on top of the host-player's object.
Cheers, Noel
Describe the bug Despawning an object leads to warning message "Trying to destroy object N, but it doesn't seem to exist anymore!" Note this happens when running as Host, even if there are no other players connected. Other than the warning message the object appears to be destroyed correctly and propagated to any connected clients.
To Reproduce Create a prefab with box collider set as trigger and add a script with the following code. Note the issue doesn't appear limited to this scenario, it was just the simplest example I could think of.
To spawn the object, create an empty game object and associate the following script. Point "target" at the prefab above.
Play as Host. Walk into the spawned object.
Expected behavior On collision with the spawned object, it should be despawned without logging a warning.
Screenshots N/A
Environment (please complete the following information):
Thanks, Carl