Search Issue Tracker
Fixed
Fixed in 2022.3.11f1, 2023.1.13f1, 2023.2.0b7, 2023.3.0a1
Votes
0
Found in
2022.2.12f1
2023.1.0b9
2023.2.0a8
2023.3.0a1
Issue ID
UUM-31100
Regression
Yes
[Undo] “Transform is used before Awake” error appears when accessing GameObject transform from “OnDestroy” if the GameObject is deleted by an Undo operation
How to reproduce:
1. Open the user’s attached “Bug.zip” project
2. In the Hierarchy window select “Cube” GameObject
3. Duplicate “Cube” GameObject and press undo
4. Observe the Console window
Expected result: No error
Actual result: “Transform is used before Awake. Are you trying to access scene objects from assets (ScriptableObject.OnValidate)?” or “Illegal transform access. Are you accessing a transform position from OnValidate?” error appears
Reproducible with: 2022.1.0a12, 2022.1.24f1, 2022.2.12f1, 2023.1.0b9, 2023.2.0a8
Not reproducible with: 2020.3.46f1, 2021.3.21f1, 2022.1.0a11
Reproduced on: macOS 13.2.1 (Intel)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Crash on TextCore::OTL_TableReader::GetOpenTypeLayoutTables when using Japanese Font as TMP Fallback
- TreeView.AddItem performance regression when opening EditorWindow
- Shadows are not visible in Player when using DX12 with Forward+ or Deferred+ rendering in URP
- Rendering Debugger Playmode debug UI scrolling is jittery when using click and drag to scroll
- Frame Debugger Target Selection Search Results window becomes too tiny to even see the default “Editor” selection when there are no search results
Resolution Note (fix version 2023.3.0a1):
Accessing Transform data from “OnDestroy” during an Undo operation is no longer allowed. Transforms are detached from each other and reassembled during Undo operations so we can therefore no longer return any transform data like position and rotation during Undo operations. Instead a better error messsage is now logged so it can be fixed on from the client side: "Transform cannot be used during an Undo operation. Use 'Undo.isProcessing' to check before accessing."
Example code for a Monobehaviour that is fixed up and handles the Undo case:
[ExecuteAlways]
public class test : MonoBehaviour
{
void OnDestroy()
{
#if UNITY_EDITOR
if (!Undo.isProcessing)
Debug.Log("Editor: " + transform.position);
#else
Debug.Log("Player: " + transform.position);
#endif
}
}
Resolution Note (fix version 2023.1.13f1):
Fixed in: 2023.1.13f1
Resolution Note (fix version 2022.3.11f1):
Fixed in: 2022.3.11f1