User Tools

Site Tools


dragengine:modules:dragonscript:behavior_attachable

This is an old revision of the document!


ECBehaviorAttachable

Behavior element behavior adding support to be attached to an ECBehaviorAttachSlot.

While ECBehaviorAttachToParent behavior allows to attach objects by using the IGDE World Editor the ECBehaviorAttachable behavior allows to attach objects at runtime into attachment slots provided by ECBehaviorAttachSlot.

This behavior knows how to attach to ECBehaviorAttachSlot containing an ECBehaviorCollider.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix attachable. .

Events

This behavior has these events:

attachableAttached

Attachable has been attached to slot.

attachableDetached

Attachable has been removed from slot.

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present.

attachable.detach

Detach element from attach slot if attached to an attach slot.

ParameterValueDescription
dispose If present element is disposed after detaching, even if not attached before. Action returns BTResult.running to stop the behavior tree.

This is an example of using this action:

<action name='attachable.detach'>
  <parameter name='dispose'/>
</action>

attachable.check

Check one or more attachable parameters. Action succeeds if all parameter value matches their respective attachable parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a attachable parameter matches (or not).

ParameterValueDescription
attachedtrue, falseElement is attached to an attach slot or not

This is an example of using this action:

<sequence>
  <action name='attachable.check'>
    <parameter name='attached'>true</parameter>
  </action>
  <!-- actions here run only if element is attached to a slot -->
</sequence>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace attachable with attachable(id).

attachable.check

Check one or more attachable parameters. Conditions returns true if all parameter value match their respective attachable parameter. This condition is typically used to run an action or sequence of actions as long as attachable conditions are true.

ParameterValueDescription
attachable.attachedtrue, falseElement is attached to an attach slot or not

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='attachable.attached'>true</parameter>
  <condition>attachable.check</condition>
</action>

Required Behaviors

Optional Behaviors

Persistency

This behavior does support element class to be persistable (setPersistable).

API Documentation

ECBehaviorAttachable.

Since DragonScript Module Version 1.0

Use Cases

Element Class Example

This example defines an element which can be attached to ECBehaviorAttachSlot.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  public var ECBehaviorAttachable attachable
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    attachable = ECBehaviorAttachable.new(this, collider)
  end
end

Behavior Factory

Using element class supporting adding behaviors the behavior can be added like this:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorComponent'/>
  <behavior type='ECBehaviorCollider'/>
 
  <behavior type='ECBehaviorAttachable'>
    <!-- optional: use behavior tree with id instead of empty string -->
    <string name='behaviorTree'>second</string>
 
    <!-- optional: use state machine with id instead of empty string -->
    <string name='stateMachine'>second</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.name'>value</string>
  </behavior>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_attachable.1746221803.txt.gz · Last modified: 2025/05/02 21:36 by dragonlord