Why would I get the following log?
- Start OpponentMotionReceiver
- motion receiver not found
- true
public class ScoreAnimation : MonoBehaviour
{
private OpponentMotionReceiver cachedObject;
private void Start()
{
cachedObject = FindObjectOfType<OpponentMotionReceiver>();
}
private void OnDestroy()
{
var motionReceiver = FindObjectOfType<OpponentMotionReceiver>();
if (motionReceiver == null)
{
Debug.Log("motion receiver not found");
}
if(cachedObject != null)
{
//prints true, another proof that the gameObject is active
Debug.Log(cachedObject.gameObject.activeInHierarchy);
}
}
}
public class OpponentMotionReceiver : MonoBehaviour
{
private void Start()
{
Debug.Log("Start OpponentMotionReceiver");
}
private void OnDisable()
{
//never enters
Debug.Log("OnDisable OpponentMotionReceiver");
}
private void OnDestroy()
{
//never enters
Debug.Log("OnDestroy OpponentMotionReceiver");
}
}
P.S. This is extremely simplified version of the code so that the rest brings no confusion. If you need more details, I’d be pleased to answer you!