Game Development Community

BehaviorInstance::getTemplateName returns null

by And Yet It Moves · in Torque Game Builder · 07/13/2007 (6:17 am) · 2 replies

Hi,

since i switched to 1.5 release my behaviors behave rather weird (some behavior methods can't be found, i did not yet check which exactly are broken, we have many nested behaviors...). my first guess is that it has something to do with getTemplateName() always returning null?

[edit1]
i just saw that BehaviorTemplate::createInstance returns a BehaviorTemplate instead of a BehaviorInstance. thats why calling getTemplateName on the returned object doesnt work...
doesnt the BehaviorInstance class exist anymore? or am i just too confused now
[/edit1]

#1
07/13/2007 (11:55 am)
AYIM,
I think you're confused. the BehaviorTemplate class does return a BehaviorInstance when you call createInstance. Is there a documentation slip-up that's confusing you?

The new behaviors release is slightly more restrictive about how it recurses to call behaviors as to prevent people from entirely nuking themselves getting stuck in a recursive loop calling into owner, back into the behaviors, and into the owner, etc..

If you check out the behaviorComponent.cpp file in _callMethod you'll see some code-review comments that cover this. Snippet below

// [neo, 5/10/2007 - #3010]
   // We don't want behaviors to call a method on its owner which would recursively call it
   // again on the behavior and cause an infinite loop so we mark it when calling the behavior
   // method and trap it if it reenters and force it to call the method on this object.
   // This is a quick fix for now and I will review this before the end of the release.

Hope this helps!

-Justin
#2
07/14/2007 (1:06 am)
Ok sorry i compared this to beta3 now and it was the same there, so this is not the reason for our misbehaving code. but here is what confused me:

create some Behavior MyBehavior and call

$bla = MyBehavior.createInstance();
echo($bla.getTemplateName());

this will return

<input> (0): Unknown command getTemplateName.
  Object (2101) MyBehavior -> BehaviorTemplate -> SimObject

but if you type in

$bla.dumpClassHierarchy();

you'll get

BehaviorInstance ->
SimObject ->