{{tag>dragonscript behavior}} [[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorAttachToParent** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== 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 [[behavior_attachslot|ECBehaviorAttachSlot]]. This attach method can only be used if these requirements are fulfilled: * The stub property name ''attachToParent.attachSlot'' is present * This element has [[behavior_attachable|ECBehaviorAttachable]] * The target element has [[behavior_attachslot|ECBehaviorAttachSlot]] with matching name If any of these requirements are not fulfilled an exception will be thrown. If target element contains [[behavior_collider|ECBehaviorCollider]] regular attaching is used. An optional ''bone'' property is supported to allow attaching the element to a specific bone in the target object [[behavior_collider|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. * Full name: ''attachToParent.bone'' * Type: string * Default Value: empty string * Example (*.deeclass) hand.attach.l ===== attachSlot ===== Set behavior identifier of attach slot to attach to. * Full name: ''attachToParent.attachSlot'' * Type: string * Default Value: empty string * Example (*.deeclass) hand.l ===== relative ===== Set attach relative to world position or using explicit position. * Full name: ''attachToParent.relative'' * Type: boolean * Default Value: ''true'' * Example (*.deeclass) false ===== rigMode ===== Set attach using rig mode if supported by colliders. * Full name: ''attachToParent.rigMode'' * Type: boolean * Default Value: ''true'' * Example (*.deeclass) false ===== position ===== Set explicit attach position. * Full name: ''attachToParent.position'' * Type: 3-component float vector * Default Value: (0,0,0) * Example (*.deeclass) ===== orientation ===== Set explicit attach rotation to attach resource to collider in degrees. * Full name: ''attachToParent.orientation'' * Type: 3-component float vector * Default Value: (0,0,0) * Example (*.deeclass) ====== Events ====== This behavior has no events. ====== Required Behaviors ====== * [[behavior_collider|ECBehaviorCollider]] ====== Optional Behaviors ====== * [[behavior_attachable|ECBehaviorAttachable]]: Support using [[behavior_attachslot|ECBehaviorAttachSlot]] targets. ====== Persistency ====== This behavior does not required element class to be persistable (setPersistable). ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorAttachToParent.html,ECBehaviorAttachToParent~@#. Since DragonScript Module Version ''1.0'' ====== Use Cases ====== * Attach element to parent element set in world editor. * Attach element dynamically using game scripts. ====== 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: value ====== Live Examples ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]