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 ?

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

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 :wink: