- Home /
Why does gameObject.SetActive (false) doesn't work???
Hi,
I have a serious problem with my script.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Plane_swap : MonoBehaviour, IPointerClickHandler
{
public GameObject plane;
public GameObject plane2;
public void OnPointerClick(PointerEventData eventData)
{
plane.SetActive (false);
plane2.SetActive (true);
}
}
When I launch it in editor mode, it works perfectly. HOWEVER, when I build & run my project(for Windows), it's not that great. Although function SetActive(true) works as intended, SetActive(false) doesn't(or so I think) for planes show up at scene, but they don't dissapear after deactivating them.
Here's bunch of screenshots, that depict my issue:
When you take a closer look at the screenshots from build & run mode, you can see that behind the currently active plane, there are all previously activated planes.
By the way, may you explain my the reason for such a difference between colours in edit mode and in build & run mode???
Are you in Free Aspect? Also, the Scene view is not the Game view so the one you need to look at is the GameView. Scene view is for working only.
I've never heard of a problem with SetActive(false)
not working.
There's probably a mistake somewhere else -- not setting those particular planes to false, or overly complicated code setting back to true.
Since plane and plane2 are publics, you can check them while paused. $$anonymous$$ight help.
I agree with Owen Raynolds, SetActive should definitely toggle the whole GameObject reliably. If that was an issue I think the forum would go crazy about it. $$anonymous$$aybe you should disable everything except this script and see what happens.
@fafase Yup, scene view is not the game view, that's why you have them both.
@Owen Reynolds @ hexagonious How can I pause in a Build & Run mode. Becuase when I'm in editor mode this issue doesn't appear neither on scene view nor on game view. $$anonymous$$aybe that's why not many people were talking about it(though I found some).
By Build & Run $$anonymous$$ode, you mean built and run on a mobile device? During game there's only the fake pause by setting Time.timeScale to 0 I would definitely try to achieve the result without code for the device until that works and then look what I had really changed to get that result. Then code it up. Only because it's not working of course.
Your answer

Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
My Build won't run properly on Win 8.1 0 Answers
SetActive Button from another scene isn't working in build 0 Answers
Game Camera not scaling correctly when built. 1 Answer
Blank result from build and run 3 Answers