Search Issue Tracker
Third Party Issue
Third Party Issue in 6000.0.X
Votes
2
Found in
2021.3.38f1
2022.3.27f1
6000.0.0f1
Issue ID
UUM-72568
Regression
No
"NullReferenceException: Object reference not set to an instance of an object" error is thrown in the Play Mode when the project is reopened with a Prefab GameObject selected in the SerializedField
How to reproduce:
1. Open the “bug test“ project
2. Open the “SampleScene“
3. Drag and Drop “Button“ Prefab to the Scene
4. Open the “Main Camera“ GameObject in the Inspector
5. In the “Game Manager (Script)“ Component add the “Button“ GameObject in the “Element 0“ field
6. Save the project and reopen Unity
7. Enter the Play Mode and observe the Console window
Expected result: No errors are thrown and clicks on the button are logged in the Console
Actual result: “NullReferenceException: Object reference not set to an instance of an object. GameManager.Start()” error throw, clicks on the button are not logged in the Console
Reproducible with: 2021.3.38f1, 2022.3.27f1, 6000.0.0f1
Reproducible on: macOS 13.5.2 (Intel), Windows 10 Pro (2H22)
Not reproducible on: No other environments tested
Workaround:
1. Open the “Button“ GameObject in the Inspector
2. Remove the “Button (Script)“ Component
3. Add “Button (Script)“ Component
4. Open the “Main Camera“ GameObject in the Inspector
5. In the “Game Manager (Script)“ Component add the “Button“ GameObject in the “Element 0“ field
Notes:
- After the workaround, the “Game Manager (Script)“ Component will function as expected until the next Unity reopening
- Only reproducible with Prefabs
Comments (3)
-
gavinclester
May 23, 2024 03:50
Making a game with skins, this issue is making the skin selection process more difficult…
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
- Required SpriteMask class (ID 331) is stripped when "Strip Engine Code" is enabled
- “Maximized serialized file backup not found” error is thrown when minimizing a window in a newly opened project
- Build stack trace contains invalid lines when building with IL2CPP using scripts with delegates containing generic types in the signature
- Entities Systems window has a “Show Full Player Loop” dropdown which does nothing when clicked after enabling “Show Full Player Loop”
- Entities Hierarchy Search “Show/Hide” button’s Lens Icon is blurry when the Editor is on an external monitor
Resolution Note:
By default Unity calls Start() in unspecified order between MonoBehaviours which means that we can call:
GameManager.Start()
Button.Start()
or
Button.Start()
GameManager.Start()
When GameManager.Start() is called before Button.Start() adding new events to Button.actions will result in a null pointer exception because Button.actions is not initialized. Initialization of Button.actions can be done in Button.Awake() instead of Button.Start() to make sure Button.actions is not null when GameManager.Start() is called.
Another option is to use Script Execution Order settings (https://docs.unity3d.com/Manual/class-MonoManager.html) to make sure Button.Start() is called before GameManager.Start().
Resolution Note (6000.0.X):
By default Unity calls Start() in unspecified order between MonoBehaviours which means that we can call:
GameManager.Start()
Button.Start()
or
Button.Start()
GameManager.Start()
When GameManager.Start() is called before Button.Start() adding new events to Button.actions will result in a null pointer exception because Button.actions is not initialized. Initialization of Button.actions can be done in Button.Awake() instead of Button.Start() to make sure Button.actions is not null when GameManager.Start() is called.
Another option is to use Script Execution Order settings (https://docs.unity3d.com/Manual/class-MonoManager.html) to make sure Button.Start() is called before GameManager.Start().