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
- Light Anchor component has non-zero default values for Elevation when adding a new Light Anchor component
- Inspector elements are rendered twice when the script component is added via drag-and-drop while the HideFlags.HideInInspector property is set
- Error "Light baking failed with error code 5 (Convergence data not available while rendering lightmaps)" thrown in Console when generating lighting for specific GameObjects
- Copy and Paste options for an Animation Property value are disabled in the Right click contextual menu
- Asset is not found when searching the Label "NewLabel" in Search Window
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