At certain points in my game the PlayerController/object picks up another gameObject which temporarily becomes a child of the player. (I say temporarily as the picked up object has a destroy by time script on it)
Anyway… how can I check if this child object is present on the parent?
Maybe just comparing transform to null will solve Your problem?
Example:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour
{
GameObject go;
Transform t;
void Start()
{
go = new GameObject();
t = go.transform;
Destroy(go, 2f);
}
void Update()
{
if (t == null)
Debug.Log("Object does not exist");
else
Debug.Log("Object exists");
}
}
Old thread but if anyone needs, you could use a try catch
bool childExists = false;
try
{
child = GetComponentInChildren<Transform>(); // Replace Transform with any other script that would only be on this child
childExists = true;
}
catch{
}