Table of Contents

,

Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorAttachToParent

ECBehaviorAttachToParent

Behavior element behavior adding attach to parent support.

Objects can be attached to parent objects in the IGDE World Editor. During enterFrame() BehaviorElement sets the target object as the parent object. The actual attaching needs knowledge about the target object. This is delegated to behavior instances knowing how to do the attaching.

This behavior knows how to attach to BehaviorElement instances. By default the element to attach to is expected to a BehaviorElement. The element will be casted to BehaviorElement and attachToBehaviorElement() called. Optionally an ElementVisitor can be set which disables the default behavior and visits the element instead. This is useful for complex situations where even non-BehaviorElement elements can be used.

If the stub property attachToParent.attachSlot is used the element is attached to the named target ECBehaviorAttachSlot. This attach method can only be used if these requirements are fulfilled:

If any of these requirements are not fulfilled an exception will be thrown.

If target element contains ECBehaviorCollider regular attaching is used.

An optional bone property is supported to allow attaching the element to a specific bone in the target object ECBehaviorCollider given the collider is a ColliderRig or ColliderComponent instance.

If no bone property is used and both colliders are ColliderRig or ColliderComponent and both used rigs have bones then rig attachment is used. This is typically used to attach cloth to actors copying the actor bone states to the cloth bone states.

In all other cases static attaching is used.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix attachToParent. .

bone

Set bone to attach to.

attachSlot

Set behavior identifier of attach slot to attach to.

relative

Set attach relative to world position or using explicit position.

rigMode

Set attach using rig mode if supported by colliders.

position

Set explicit attach position.

orientation

Set explicit attach rotation to attach resource to collider in degrees.

Events

This behavior has no events.

Required Behaviors

Optional Behaviors

Persistency

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

API Documentation

ECBehaviorAttachToParent.

Since DragonScript Module Version 1.0

Use Cases

Element Class Example

This example defines an element which can be attached to other elements.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  public var ECBehaviorAttachable attachable
  public var ECBehaviorAttachToParent attachToParent
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    attachable = ECBehaviorAttachable.new(this, collider)
    attachToParent = ECBehaviorAttachToParent.new(this, collider, attachable)
  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'/>
 
  <behavior type='ECBehaviorAttachToParent'>
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.name'>value</string>
  </behavior>
</elementClass>

Live Examples