- Home /
Particular Child Object Refuses to setActive - Others work fine
I could probably just do this some other way. Maybe I will end up doing so (I suspect this setup is subpar to begin with). That said, I'm ticked off enough by the opaque nature of the problem that I thought I'd submit it here in the hopes that someone might recognize where the trouble's coming from, and help me to clear it up, just for the satisfaction of ridding a bug from the world.
I have child objects in my 2D ship that're used as engine flame animations. There's currently separate forward and rear animations that play depending on which direction the player is thrusting, and normal and 'afterburner' or "boosted" sets, for a total of four different animations to keep track of.
Three of the four work fine. One of them (activated by the section which I have placed asterisks around here for the purposes of easy identification) doesn't show up at all, for no apparent reason. If I switch it to use any animation besides the one that is relevant to the situation (like using the boosted thrust for both normal and boosted) that works just great. The only thing that doesn't is the one that is supposed to be there. I've used print statements to show that it does access that code, it just doesn't turn the child object on. I've switched the code around (a previous iteration was written just about upside-down from this) to test whether anything was wrong with that animation, but no, it's fine -- it just doesn't get loaded by that particular segment of code.
Have a look at this mess:
void EngineActivate()
{
if (boost == 0) {
if (vert > 0) {
transform.GetChild(0).gameObject.SetActive (true);
transform.GetChild(1).gameObject.SetActive (false);
} else
**transform.GetChild(2).gameObject.SetActive (true);
transform.GetChild(3).gameObject.SetActive (false);**
}
else if (vert > 0) {
transform.GetChild(1).gameObject.SetActive (true);
transform.GetChild(0).gameObject.SetActive (false);
} else
transform.GetChild(3).gameObject.SetActive (true);
transform.GetChild(2).gameObject.SetActive (false);
}
Try setting them up as variables and reference them in the inspector public Transform child1; etc and see if it works, it might be that the GetChild method returns a null