MirrorNetworking / MirrorNetworking/Mirror

Scene prefab instance invokes custom unspawn instead of deactivating in NetworkClient.DestroyObject

Open
#3,574 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
C#
Stars
6.3k
Forks
870
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
Prefabs placed in a scene, but also registered via RegisterPrefab will invoke the custom unspawn handler instead of being deactivated and added back to spawnableObjects and Reset.

[IMPORTANT] How can we reproduce the issue, step by step:

  • Using Tanks as an example.
  • Create a new prefab (Cube with a NetworkIdentity component is fine)
  • Place it in the scene in the center of the Tanks sample
  • Add code to the tanks example to call RegisterPrefab with this prefab and give it a custom unspawn handler (just destroy the object like you would in the simplest possible unspawn handler)
  • Add DistanceInterestManagement to Tank example, dist=3 (this allows us to test unspawning on the client)
  • Run the sample as host in a stand alone app
  • Run the client in editor.
  • Move the client tank towards the center and the object will appear (correctly)
  • Move the client tank away from center and the object will be destroyed (incorrect)
  • Move the tank back towards the center and an error will be reported in the console

Spawn scene object not found for 7A7BE7168BCD866C. Make sure that client and server use exactly the same project.

Expected behavior
Would not expect scene objects to invoke custom unspawn handlers since they don't invoke custom spawn handlers.

Desktop (please complete the following information):

  • OS: MacOS
  • Build target: standalone
  • Unity version: 2021.3]
  • Mirror branch: 73.0

Additional Notes
It's also invalid to pass null to RegisterPrefab for the unspawn handler (so this can't be worked around easily)

The code causing this behavior also exists in DestroyAllClientObjects but I don't have a repro for an issue caused by it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at NetworkClient.DestroyObject and compare its scene-object handling with the custom unspawn path; also inspect the related code in DestroyAllClientObjects. Reproduce using the Tanks sample, RegisterPrefab, a custom unspawn handler, and DistanceInterestManagement. Done means scene prefab instances deactivate and return to spawnableObjects and Reset without the missing scene object error.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, unity
Domain
game-dev, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.