Can you set a script not to compile on playtest?

Hey guys,

Possibly a stupid question but is there anyway to disable a script in the inspector so it won’t compile on playtest.

When your playing around in darkness as I am with my inept abilities to script its really frasturating messing something up that was ‘kind of’ working previously. Also im using alot of example scripts and changing them to suit my needs and ‘trying’ to convert them from Java to C# (thinking of course that ideally a game should be made in a single language and not have 1 script in java the next in C# etc).

This does however mean that I copy a script from the interwebs, which maybe in java, fire it up in my project to figure out how it works and then try and write a C# script to do the equivilent…however when my attempt does not work im unable to playtest and retest the Java script which works becuase of the compile errors my script causes.

So is there anyway I can set the inspector just to ignore certain scripts on play test?

Regards,

John

P.s looks like I might be looking for a programmer sooner rather than later…get back to doing what im good at, making art :slight_smile:

Scripts aren’t compiled when you hit Play - they are compiled each time the workspace refreshes. So, no I don’t think so. You can, of course, just move the script out of your project and reference it elsewhere.

Or comment out the entire file.

–Eric

Yes you can disable scripts, there should be a check mark next to the script name in the inspector. Simply uncheck that and there you go.

Yeah i believe you can write a line of code in the awake function like

(GetComponent<"ScriptName"> as ScriptName).enabled = false;

or something along them lines look into it

should disable the script during playtest

It looks like the OP is looking to stop the scripts compiling (presumable due to compilation errors), not disable them. Although as pointed out scripts are compiled when the workspace is refreshed not before or during “playtest”.

Just “this.enabled = false;” or even “enabled = false;” would do it - a script doesn’t need to find itself. :wink: But just disabling it in the Editor is the best solution.

What’s the underlying reason for wanting to disable things to avoid screwing them up, though? As in, what’s the actual problem that you’re running into here? Perhaps we can help with that.

That won’t have any effect on scripts with errors that won’t compile. The solutions have already been posted: put the scripts outside the project so Unity doesn’t see them, or comment out the entire file. Actually, another one: rename the script so it ends with .txt instead of .cs, then it won’t try to compile at all.

–Eric

Just a thought, if disabling the script from the inspector is not a strict requirement.
In MonoDevelop/VS you can use compiler variables to “comment out” sections of code that should not be compiled, maybe they can be useful.
You define a BUILD compiler variable and then enclose the unbuildable script in #if !BUILD … #endif
Be aware that I did not try this in Unity, this is how it works in general.

Yup that will work in Unity too, for this purpose its probably not much more useful than sticking comments around the code, but good to explore all the options :slight_smile:

Cheers all for the help.

Angry Penguin, im sure ill be back asking silly questions concerning those problems soon enough, shouldn’t encourage it :).

Eric’s idea sounds like what I want, just rename the file to a .txt or similar. I did have a temp folder set up outside the project folder to ‘dump’ files I didn’t want processed on previews but ended up replacing the wrong file and thought there must be a better way than that.

Many Thanks Everyone,

John