I'm having a very frustrating issue with GetComponent().
private void Show()
{
var transition = GetComponent<TransitionAnimation>();
Debug.Log($"Transition: {transition}");
transition?.FadeIn();
}
In the editor, this works just fine. transition is not null and FadeIn() is called. In the standalone build, GetComponent() returns null, throws a NullReferenceException, and execution stops before it can even print transition to the console.
This is the output from the log file.
Uploading Crash Report
NullReferenceException
at (wrapper managed-to-native) UnityEngine.Component.get_gameObject(UnityEngine.Component)
at UnityEngine.Component.GetComponentInChildren (System.Type t, System.Boolean includeInactive) [0x00001] in <e314adc5a7494b5f8760be75461a94d4>:0
at UnityEngine.Component.GetComponentInChildren[T] (System.Boolean includeInactive) [0x00001] in <e314adc5a7494b5f8760be75461a94d4>:0
at Winglett.RR.UI.Gradient.Show () [0x00001] in /Users/redacted/Documents/repos/radical-relocation/Assets/_Core/Scripts/UI/Gradient.cs:63
at (wrapper delegate-invoke) <Module>.invoke_void()
at Winglett.RR.Gameplay.GameState.SetPause () [0x00001] in /Users/redacted/Documents/repos/radical-relocation/Assets/_Core/Scripts/Gameplay/GameState.cs:46
at Winglett.RR.Gameplay.GameState.SetPause_STATIC () [0x00000] in /Users/redacted/Documents/repos/radical- relocation/Assets/_Core/Scripts/Gameplay/GameState.cs:70
at Winglett.RR.UI.Wrapper.SetGameStatePause () [0x00000] in /Users/redacted/Documents/repos/radical-relocation/Assets/_Core/Playground/ui/Wrapper.cs:27
at UnityEngine.Events.InvokableCall.Invoke () [0x00011] in <e314adc5a7494b5f8760be75461a94d4>:0
at UnityEngine.Events.UnityEvent.Invoke () [0x00023] in <e314adc5a7494b5f8760be75461a94d4>:0
at Winglett.RR.Utils.ESCButton.Update () [0x00026] in /Users/redacted/Documents/repos/radical-relocation/Assets/_Core/Scripts/Utilities/Other/ESCButton.cs:21
I wondered if the issue might be because the gameobject is disabled. So I tried GetComponentInChildren<TransitionAnimation>(true); where true is an overload for inactive gameobjects. This didn't change anything.