Disabled object script is running?

I have a script that I use on fire and water spouts to turn them off and on, on a timer. They are both under a disabled object, so they absolutely should not be running the code on them.
The fire spout doesn’t run code until the parent object is enabled(as it is supposed to). However, the water spout code is running even when the parent object is disabled. This has never happened to me before and it extremely confusing. Even if I go to the water spout object and disable it directly, or disable the script directly, the code still runs. I’ve tested this by making the “TriggerOrPlatform” gameobject be the player. The player is still disabled and enabled even if the waterspout code is disabled and object is disabled. They are both using the exact same script. I’m completely baffled by this.

This is the code on both of the objects:

#pragma strict

var Particles : ParticleSystem;
var TriggerOrPlatform : GameObject;
var Delay : float;
var ObjectWithLift : GameObject;


function Start () {
	TurnOn();
	Debug.Log("I'm enabled");
}


function OnEnabled () {
	TurnOn();
	Debug.Log("I'm enabled");
}

function TurnOn()
{
	Debug.Log("I'm turning on" + this.gameObject);
	TriggerOrPlatform.SetActive(true);
	if(ObjectWithLift != null)
		ObjectWithLift.SetActive(true);
	TriggerOrPlatform.SetActive(true);
	Particles.Play();
	
	Invoke("TurnOff", Delay);
}

function TurnOff()
{
	TriggerOrPlatform.SetActive(false);
	if(ObjectWithLift != null)
		ObjectWithLift.SetActive(false);
	Particles.Stop();
	Invoke("TurnOn", Delay);
}

Hi !

  • In your TurnOn function you use TriggerOrPlatform.SetActive(true); two times, only one is needed (since you interact with other stuff inbetween). That’s not related but i saw that ^^

  • About your issue, you don’t seem to set any value to your delay float (unless you do it from an other script ?), it may come from here :slight_smile: