- Home /
Prevent a script from compiling ?
Hi, I would like to ship with my package(which already has several scripts) a new script. This script can only be used if the user has the Character Controller in the project. (The script tries to get the CharacterMotor component)
So if you import the package and the Character Controller is not in the project, you will get compilation errors. And my "clients" don't necessarily use the Character Controller.
Is there a way to prevent this script from compiling until it's actually used on an object ?
Well, you could short-circuit the whole thing by just including the Character$$anonymous$$otor script as a dependency of your script in the UnityPackage...
Thank you. That would temporarily work, but when Unity updates the scripts it will be a mess to distinguish between my and their version.
Answer by Dreamora · Dec 13, 2011 at 10:46 AM
No, scripts in the project are always included. If you don't want them to be included, don't drop them into the project until you need them.
Its for code impossible to decide whats used and what not as you can use and create instances of classes from other classes not just cause they are on an object.
but generally code is no problem at least if it uses the unity engine only cause the engine is present anyway
Answer by Bunny83 · Dec 13, 2011 at 07:05 PM
Another way would be to rename your script (to *.txt for example) and than use an editor script which checks the project for the CharacterMotor class and automatically rename and reimport the script if needed. However this check have to be executed in some way after you've added the package to the project. An AssetPostProcessor is usually a good point to start with, but i guess it won't help when you import it together with the package (I guess it can't post process it's own package, at least not the first time).
Another problem is that you can't ship perfabs which use the script because you "removed" it from the package since you ship it as text-asset.
It's better to use seperate packages ;)
I'm glad we agree :) Thank you for the brainstor$$anonymous$$g !
Your answer
Follow this Question
Related Questions
Exporting and keeping scripts 0 Answers
How to sprint and have a stamina bar? 0 Answers
Scores/points when you destroy something? 1 Answer
Attach a animation to 0 Answers
Editor Scripts in Dll 1 Answer