- Home /
!IsActive && !GetRunInEditMode
I'm setting active with SetActive on a gameobject and I'm getting this error when I run the game and it hits that line of code. It appears to be running fine, but would like to understand and clear this out. Anybody ever get this error? I don't want to post code because it would be a lot of code and I can just work around it.
Please post the exact error message, I don't get what error message you have?
All it says is !IsActive && !GetRunInEdit$$anonymous$$ode as an red error message. It doesn't say anything else.
O$$anonymous$$ this looks uncommon to me. Is your gameObject not active by default?
It's active upon starting. I'm just disabling a script right now ins$$anonymous$$d of the whole gameobject so it's fine. Just thought I would post it in case someone else had the same error.
As a starting point, double click on the error and look in $$anonymous$$ono for the script and line the error is co$$anonymous$$g from. I remember getting this error in EZGUI at one point, but I don't remember how I fixed it.
Answer by gStormDesign · Aug 05, 2013 at 04:56 PM
I got the same obscure error message that appears to be a lost debugging trap for an odd condition.
By way of example, my case was narrowed down to a gameObject.SetActive(false) call from within the OnGUI method, as opposed to Update() or FixedUpdate().
Presumably, the tick cycle chain should be respected for cases where a game object can deactivate itself, and these operations should be performed outside OnGUI(). Hope that helps.
I had the same problem and solution, I was setting this.gameObject.SetActive(false) inside the OnGUI. The solution was triggering a boolean within OnGUI that in Update would SetActive(false)
Thanks ! Do setactive outside OnGui() function solve me :D
Answer by Gurunext · Feb 22, 2014 at 02:54 AM
Yes I had the same problem/error. And it all happens if I try to disable gameobject in OnGUI as described. OnGUI happens more than one tick and for different events. If the correct event does not occur you function won't work. For example if you are pressing a button to deactivate gameobject you would find two events: "Layout and mouseDown". You can simply filter events with IF statement
if (Event.current.type == EventType.mouseDown)
gameobject.SetActive(false)
Answer by unmaxim · May 24, 2014 at 01:54 PM
I fixed that problem by removing the following DLL: "Assets/Plugins/UnityEditor.dll"; Note that after removing Unity will probably update it's interface to original (all your internal windows settings will be discarded)
Answer by Kaworuyoshi90 · Aug 15, 2014 at 07:57 PM
This is because you are trying to disable an object that it's in the middle of something, at least that was happend to me, my solution was call the method or copy the code to another method wich the same number of calls from MonoBehaviour, for example: my code was like this: void OnGUI() { deactivateChilds(); }
void deactivateChilds()
{
for( int i = 0; i < transform.childCount; i++ )
{
transform.GetChild(i).gameObject.SetActive(false);
}
}
and the solution was to call deactivateChilds() from the Update method.
Answer by BulwarkAssassin · Mar 10, 2019 at 07:29 PM
In my case I had a "HideGui()" function being called from "OnGui()" whenever the H key was pressed, which toggles the active state of the canvas between "Canvas.SetActive(true)" and "Canvas.SetActive(false)". My solution was to convert the "HideGui()" function to a coroutine and add the line "yield return new WaitForEndofFrame()" at the beginning. This ensures that whatever other activities in other scripts that were being performed on the canvas have the opportunity to resolve for that frame before the canvas is deactivated. This resolved all of my errors.
Your answer
Follow this Question
Related Questions
GameObject[] Issues 1 Answer
Need workaround for this line of code 1 Answer
SetActive over network 1 Answer
I Can't disable gameObject using .SetActive (or anything else) 2 Answers
Can't activate game object. 3 Answers