x


Script Not staying disabled

Has anyone else come across this? A script that I disable with the code below disables for an instant, then doesn't stay disabled any longer (I know this by debugging).

GameObject.Find("Terrain").GetComponent("TerrainScript").enabled=false;

I don't have it being enabled anywhere in my code and I can't figure out why it becomes enabled again. TerrainScript does have a Update function but I can't imagine that making a difference.

more ▼

asked May 07 '10 at 01:31 AM

Jordan Miller 2 gravatar image

Jordan Miller 2
348 47 51 57

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

For debugging purposes, one thing I like to do is break down any multiple-step statements, and check that every step worked. For instance, you could do:

var foo = GameObject.Find("Terrain");
if (foo == null) {
    Debug.Log("wups");
}
// then get Component next, etc...

It's possible that something is breaking somewhere (maybe mispelling/typo), and it's not obvious.

Also - what do you mean by not disabled? I can't find the Answer again, but I remember Duck posting somewhere, that disabling a script only disables certain functions, like Update(), etc. Some things - specifically OnMouseUp(), for instance, stay enabled, and so the script will respond to mouse clicks.

Is that what's happening?

more ▼

answered May 21 '10 at 02:38 PM

Cyclops gravatar image

Cyclops
7.1k 33 63 115

Uhm, this is interesting... but I can't understand why. If somebody wants to stop a script why it's not possible to do that completely?

May 21 '10 at 03:32 PM GODLIKE

@GODLIKE, as @Duck pointed out to me (wish I could find it again), it enables the script to be re-enabled by mouse-click. If the script stopped responding to everything, and you wanted it re-enabled, then some other Object would have to read mouse-clicks, find the script, and enable it. Way too complex.

May 21 '10 at 03:48 PM Cyclops
(comments are locked)
10|3000 characters needed characters left

The only thing I could think of is that your code somewhere is in fact enabling it again, without you realizing it. Try putting the terrain and this script in a seperate scene, and see if it still happens.

more ▼

answered May 07 '10 at 11:25 AM

Lucas Meijer 1 gravatar image

Lucas Meijer 1 ♦♦
8k 19 43 85

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3337
x216
x135

asked: May 07 '10 at 01:31 AM

Seen: 1071 times

Last Updated: May 07 '10 at 01:31 AM