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