Behavior tab list problem in Object
Janne

Is tutorial video in behavior tab still valid?

When I try to create new behavior with video instructions, 
but I dont have new behavior visible in "Add Behavior" list?
There is automatically only these behaviors:
- IsoCharacter
- IsoActionCharacter
- TilemapCharacter
- PhysicsObject

Is there some trick, how to get custom behavior active to that "Add Behavior" list?
Thank you.

All 7 Comments
Gio

Hi Janne

As long as your behavior script file is in the scene assets and it is a valid script (that can be executed with no syntax errors), your behavior class name should appear in the list.

The video tutorial is a bit old but still mostly valid. These days you also have the option, when you create a new file, to set the file type to "Behavior". This will automatically add the script to the scene assets for you, and (optionally) you can have your file pre-filled with a simple behavior template. In fact this is the recommended way of doing it, it helps avoid some common mistakes.

One thing to watch out for, is that you should use the syntax

MyBehavior = function() {...);

and not

function MyBehavior() {...}

The latter doesn't create a global variable name, so the editor cannot know that it exists and cannot show it in the list.

Janne

Thank you. That new file "Behavior" template is great! My old js code was valid with no errors. But when I create new blank js file, and paste old js file code in it and voila! Now it is updatet and shown in behavior class list. That work fine now, but still the old js class not visible. I think my browser make that error now.

Gio

Your old file... was it definitely added to the Scripts list for you scene, in the Assets tab?

Janne

Yes it was, and I have save latest codes/files of wsc and js also. I think I have some problems with browser temp files etc..

Janne

I found this:
If I create new normal .js file, then it NOT shown in behavious list.
If I create new behavior .js file, then it WILL shown in behaviour list.

Both have same code in .js file.

Gio

This is really strange though, there is nothing in the editor code that treats behavior files differently to other script files - in fact, the editor views them all in the same way. It's the contents of the .js file that determine whether it should be displayed in the Behavior List.

So this sounds like a bug. If you can share an example project where this happens, I'd like to have a look and see if I can fix the bug.

Thanks

Janne

Hi,

I delete all browser temp files etc and start new project. Now all works as it should be.
Thank you for your time.
I was have 5 different projects, and those projects was mixed together somehow (maby browser problem).

Post a reply
Add Attachment
Submit Reply
Login to Reply