Standard Assets (Mobile) is not Standard Assets!

Just a quick update here with a Unity subtlety that tripped me up recently.  I was recently creating a “character controller to rule them all” which involved coordinating various versions of character control, almost exclusively picked from the Unity Standard Assets package.  This means that most of them were Javascript while one or two of the MonoBehaviours involved was a C# script I wrote myself.

The “character master” behavior was a C# script whose job is basically to enable/disable the various MonoBehaviours attached to the character (and camera) object to switch between various move/look schemas.  However, when I was writing this script, none of the controller types were being recognized by MonoDevelop or Unity.  I figured this was just some problem with Javascript scripts not being added to the right namespace, so I did a check and created a test MonoBehaviour type Foo.js and sure enough, I couldn’t create a Foo variable.  I thought “screw it” and just added them all as MonoBehaviours until I came across the need to access specific members of these controllers.  I could swear that I’d used Javascript-described classes in C# before…

At this point I did a little bit of poking through the docs until I noticed that Javascript classes need to be put in a subfolder of the Standard Assets folder in order for their classes to be included in the namespace.  Suddenly I realized what the problem was.  When you import the mobile assets, they are put under a special “Standard Assets (Mobile)” folder, which is NOT a special folder in the eyes of the build pipeline.

So, folks: if you are having trouble accessing your Javascript scripts from C#, make sure they’re in the Standard Assets folder, and if you’re trying to use one of the mobile scripts, you’ll have to move it from its original location to somewhere inside Standard Assets.

 

Just a heads-up to all you Unity devs out there!

~ by Schoen on August 23, 2011.

Leave a Reply

Your email address will not be published. Required fields are marked *