{{tag>dragonscript behavior}} [[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[dragengine:modules:dragonscript:abstractions|Abstraction Layers: How you want to build your Game]] >> [[dragengine:modules:dragonscript:behavior_elements|Behavior Elements]] >> **ECBehaviorAttachable** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== ECBehaviorAttachable ====== Behavior element behavior adding support to be attached to an [[behavior_attachslot|ECBehaviorAttachSlot]]. While [[behavior_attachtoparent|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 [[behavior_attachslot|ECBehaviorAttachSlot]]. This behavior knows how to attach to [[behavior_attachslot|ECBehaviorAttachSlot]] containing an [[behavior_collider|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 ====== * [[behavior_collider|ECBehaviorCollider]] ====== Optional Behaviors ====== This behavior does not support optional behaviors. ====== Persistency ====== This behavior does support element class to be persistable (setPersistable). ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorAttachable.html,ECBehaviorAttachable~@#. Since DragonScript Module Version ''1.0'' ====== Use Cases ====== * Allow element to be attached to [[behavior_attachslot|ECBehaviorAttachSlot]] present on other elements. ====== Element Class Example ====== This example defines an element which can be attached to [[behavior_attachslot|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: value ====== Live Examples ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]