Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
OcularCash

!isActive && !GetRunInEditMode

Question

"!isActive && !RunInEditMode"

I've come across this error a few times in the past after switching to 4.2 but I never really thought twice about it. But I was doing some functionality tests today and its getting annoying filling up my console. So I looked it up and it appears that OnGUI is throwing that error when deactivating or activating a weapon via its function.

My question isn't how to fix it in another function, but can it be fixed in the GUI function without having to use another function? I know i can reroute the call by activating a state check in update function but I'm hoping for an in function fix so the build will be fully functional ("works in editor, won't work properly Ina build"). Hope someone has a workaround

Share this post


Link to post
Share on other sites

12 answers to this question

Recommended Posts

  • 0

I take it nobody has an in function solution?... I guess I'm stuck with a state update. If someone runs into this issue and skims the forum for a solution and don't know how to do a state update, here's an example:

public var Weapon : GameObject;

private var WeaponActiveState : String = "Enable Weapon";

private var activatingWeapon : boolean;

function Start()

{

Weapon.SetActive(false);

}

function Update()

{

if(activatingWeapon)

{

ActivateWeapon();

}

}

function OnGUI()

{

if(GUILayout.Button(WeaponActiveState))

{

activatingWeapon = true;

}

}

function ActivateWeapon()

{

if(Weapon.activeSelf)

{

Weapon.SetActive(false);

WeaponActiveState = "Enable Weapon";

}

else

{

Weapon.SetActive(true);

WeaponActiveState = "Disable Weapon";

}

activatingWeapon = false;

}

Hope someone still has an in function solution, but til then I guess I'm stuck with it for now.

Share this post


Link to post
Share on other sites

  • 0

Toggle an objects active state in OnGUI in unity 4.2 without getting the error "!isActive && !RunInEditMode". I'm trying to do, for instance, something like this:

function OnGUI()

{

if(GUILayout.Button("toggle active"))

{

if(weapon.activeSelf)

{

weapon.SetActive(false);

}

else

{

weapon.SetActive(true);

}

}

}

But it gives me that error because its being in OnGUI. But for what I'm doing, i would rather it be called in that function

P.S. I know the script I posted earlier works, that's the out of OnGUI fix. I'm looking for in inside OnGUI fix

Share this post


Link to post
Share on other sites
  • 0

I don't know either, it's never thrown that message til I switched to 4.2. Anyone who uses my advanced drag and drop inventory system will now receive that message as well when replacing a weapon in the equipped slots because it uses the same method as my personal inventory.

I normally keep it out of OnGUI but if you notice in my post in resources, when dragging a weapon to the equip slots, there is a couple different variations of checks to verify what's in that slot. I can add more functions but I'm now over 1000 lines in that script so I'm trying to keep it in a local function if possible

Share this post


Link to post
Share on other sites
  • 0

Yeah, finished script will be around 2000 lines long because all information about every object and all functionality is being stored there... Before I incorporate the auto mod ban/sniffer since this game is going public. That'll be a chunk of change in itself after I hardcode it to the inventory.

Share this post


Link to post
Share on other sites
  • 0

I finally got a chance this morning to mess around with it. It seems only deactivating causes this error and I'm not able to work up a simple in function fix. So the only ways I'm able to get it to work is out of function. So I changed the topic for anyone who searches this error. If you want to deactivate an object that doesn't need parameters, see my second post on this thread. If it does need parameters, here is an example of how to fix it:

public var objectArray : GameObject[];

public var whichObjectToActivate : int;

private var activatingObject : int = 1000;

function Update()

{

If(activatingObject != 1000)

{

ActivateObject(activatingObject);

}

}

function OnGUI()

{

if(GUILayout.Button("Deactivate"))

{

activatingObject = whichObjectToActivate;

}

}

function ActivateObject(id : int)

{

objectArray[id].SetActive(false);

activatingObject = 1000;

}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...