User Tools

Site Tools


dragengine:modules:dragonscript:behavior_attachslot

This is an old revision of the document!


ECBehaviorAttachSlot

Behavior element behavior adding support to attach other behavior elements.

Provides an attachment slot where one ECBehaviorAttachable supporting element can be attached to. The slot behavior is responsible to persist the UniqueID of the attachable. Attachable is added to game world during addToGameWorld() if not in the game world already. Attachable is remove from game world during removeFromGameWorld() if in the game world. If attachable is present while behavior instance is disposed then attachable will be safely disposed using Element.safeDispose() .

Instance Counts

This behavior can be used multiple times on an element to add multiple attach slots. Use the behavior identifier to tell them apart.

Element Class Properties

Element class properties have the prefix attachSlot. or attachSlot({id}). if id is not empty.

bone

Set bone to attach to or empty string to attach to collider.

  • Full name: attachSlot.bone or attachSlot({id}).bone
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='attachSlot.bone'>value</string>

position

Set position in meters to attach to.

  • Full name: attachSlot.position or attachSlot({id}).position
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='attachSlot.position' x='0' y='0' z='0.2'/>

orientation

Set orientation in degrees to attach to.

  • Full name: attachSlot.orientation or attachSlot({id}).orientation
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='attachSlot.orientation' x='90' y='0' z='0'/>

Events

This behavior has these events:

slotAttached

Attachable has been attached to slot.

slotDetached

Attachable has been removed from slot.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

This behavior does support these optional behaviors:

Persistency

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

API Documentation

ECBehaviorAttachSlot.

Since DragonScript Module Version 1.0

Use Cases

Element Class Example

This example defines an element which contains an attachment slot.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  public var ECBehaviorAttachSlot attachSlot
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    attachSlot = ECBehaviorAttachSlot.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='ECBehaviorAttachSlot'>
    <!-- optional: use vrhand behavior with id. if not set ECBehaviorCollider is used -->
    <string name='vrHand'>right</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.bone'>hand.attach.l</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorAttachSlot' id='second'/>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_attachslot.1741792476.txt.gz · Last modified: 2025/03/12 15:14 by dragonlord