- Home /
SetActive is not working
I'm trying to activate a Game Object, and when I set it to true, it is not working for some unknown reason. Here is the part of the code:
private void ActivatePowerUpPlane()
{
if (score % PowerUpManager.getSecondsToWaitUntilPowerUpActivates() == 0)
{
Debug.Log("Test");
planeContainer.SetActive(true);
PowerUpManager.setSecondsToWaitUntilPowerUpActivates();
}
}
This is not the whole script, but the problem accrues in when I am trying to activate the plane game object.
btw this script is always turned on, the Debug.Log() gets called and the third function gets called as well.
Thanks.
Is there any other script active which can deactivate the game object in question?
how do you get a reference to planeContainer? i think there is the culprit since if you do findobject all the gameobjects that are not activated won't be found.
Answer by WARdd · Jan 03, 2020 at 03:08 PM
If the log is being called there's only 3 possible reasons for this:
The object referenced by planeContainer is not the right object or not enough e.g. you also need to activate a child or parent object
There is another piece of the code, maybe in another script, that is deactivating the plane again. A simple way to detect this is by adding a script to the planecontainer and filling in OnEnable() and OnDisable(), then putting logging messages inside those to see where it's being activated/deactivated from.
There's a goblin in your pc messing with your RAM
Here's hoping it's one of the first 2 options, because the third is quite a hassle to fix
Answer by Bunny83 · Jan 03, 2020 at 02:59 PM
Are you sure that the gameobject you try to activate is not a child of another gameobject which is deactivated? The activate state is inherited from the parent. Try printing
Debug.Log("planeContainer: activeSelf = " + planeContainer.SetActiveactiveSelf + " activeInHierarchy = " + planeContainer.activeInHierarchy, gameObject);
before and after you call SetActive. With SetActive you only control the activeSelf state, not if the object is actually activated. See SetActive
If that's not the issue you should be more specific what you mean by
is not working for some unknown reason