User Tools

Site Tools


dragengine:modules:dragonscript:behavior_attachable

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.

Required Behaviors

Optional Behaviors

This behavior does not support 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'>
    <!-- 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.txt · Last modified: 2025/03/12 19:40 by dragonlord