Search Issue Tracker

By Design

Votes

0

Found in

2021.3.34f1

2022.3.17f1

2023.2.5f1

2023.3.0b1

6000.0.0b11

6000.1.0a7

6000.2.0a1

7000.0.0a1

Issue ID

UUM-59991

Regression

No

Crash on Component_Get_Custom_PropTransform when using MemberwiseClone() and destroying the GameObject

-

Reproduction steps:
1. Open the attached project “BugCrashTesting.zip”
2. Open “SampleScene”
3. Enter and exit Play Mode
4. Observe crash

Reproducible with: 2021.3.34f1, 2022.3.17f1, 2023.2.5f1, 2023.3.0b1

Reproducible on: macOS Sonoma 14.0 (Intel), Windows 10 (by the reporter)
Not reproducible on: no other environment tested

First few lines of Stack Trace:

{noformat}#0 0x0000010b5d7935 in Component_Get_Custom_PropTransform(ScriptingBackendNativeObjectPtrOpaque*)
#1 0x00000173a4a7c9 in (wrapper managed-to-native) UnityEngine.Component:get_transform (UnityEngine.Component) [{0x7fae939cfa00} + 0xf9] (0x173a4a6d0 0x173a4a8c0) [0x159542a80 - Unity Child Domain]
#2 0x00000161eab7fc in mono_jit_runtime_invoke
#3 0x00000162061183 in do_runtime_invoke
#4 0x000001620610c0 in mono_runtime_invoke
#5 0x0000010c290337 in scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool){noformat}

Note: the crash happens in the {{SpawnedObj.cs}} script, at line 11

  1. Resolution Note:

    It is not possible to clone a GameObject using MemberwiseClone, it will not clone the underlying native structures which is also why the accessing transform during destroy creashes.

    To clone a GameObject use Instantiate instead, in your example write something like the below instead:

    spanwedObj.GetComponent<SpawnedObj>().objectSpawner = (ObjectSpawner)Instantiate(this);

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.