- Home /
Flickering when switching between GameObjects
I have two GameObjects (let's say a green and a red Cube).
I want to switch between the cubes with the SwitchCubes method, which is called on a button click:
public GameObject firstCube;
public GameObject secondCube;
void Awake()
{
firstCube.SetActive(false);
secondCube.SetActive(true);
}
public void SwitchCubes()
{
firstCube.SetActive(!firstCube.activeSelf);
secondCube.SetActive(!secondCube.activeSelf);
}
The switching works, BUT there is a splitsecond where NONE of the cubes are visible. I also tried to disabled/enable the renderers instead, but it's the same result. How can I avoid this and have the object replace the other instantly?
Unity 4.6.4, iOS 8.1.2, OpenGL ES 2.0, XCode 6.2
Thanks a lot in advance!
This looks to be simply a performance issue. Do you have anything else memory intensive going on?
No. And even if it was a performance issue, why is there a (at least one) frame rendered between
firstCube.SetActive(false);
secondCube.SetActive(true);
? In this case, I would rather want a drop in fps than flickering.
How are you handling the button click input? $$anonymous$$y current thought is that your SwitchCube() method may be called multiple times.
Your answer
![](https://koobas.hobune.stream/wayback/20220613195917im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Visibility based on Tags 2 Answers
Switching between items after being picked up? 1 Answer
physics.OverlapSphere colliders 1 Answer
How to switch game objects on and off? 1 Answer
Change GUI menu from one to the other 0 Answers