[Solved] Is it possible to get the behavior of an actor by code?

daverave1212

  • Posts: 44
Hello! This is the second time I am asking this, but the first time I got no responses.

How can I get the behavior of an actor (not attributes or functions, but the behavior itself)?

For example, if I have a block for collision event with an actor which has a custom behavior called EnemyBehavior, I want to get that EnemyBehavior behavior as an object. The equivalent in unity would be GetComponent<EnemyBehavior>(), which returns the EnemyBehavior behavior of that actor.

The reason I want to do this is to more easily access functions and properties from other behaviors.
Is it possible?
Thank you for your time!

« Last Edit: December 09, 2018, 05:07:51 pm by daverave1212 »

JeffreyDriver

  • Posts: 2262
Under the 'Behaviors' tab there are blocks for accessing other behaviours and setting their attributes etc.

daverave1212

  • Posts: 44
@JeffreyDriver Thanks for the answer, but this is not what I was looking for.

Fortunately, I found out that much of the code of the engine is in the Stencyl folder and I looked through it.
I found that I can get the behavior of an actor by:

myActor.behaviors.cache.get("BehaviorName").script

Should also cast it as:

cast(myActor.behaviors.cache.get("BehaviorName").script, MyScriptClass)

Hope it might help someone later!