{{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]] >> **ECBehaviorAttachSlot** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== ECBehaviorAttachSlot ====== Behavior element behavior adding support to attach other behavior elements. Provides an attachment slot where one [[behavior_attachable|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() . Behavior supports using [[behavior_vrhand|ECBehaviorVRHand]] instead of [[behavior_collider|ECBehaviorCollider]] to add attachment slot to VR hands. ====== 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) value ===== 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) ===== 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) ====== Events ====== This behavior has these events: ===== slotAttached ===== Attachable has been attached to slot. ===== slotDetached ===== Attachable has been removed from slot. ====== Behavior Tree Actions ====== This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''attachSlot'' with ''attachSlot(id)''. ===== attachSlot.detach ===== Detach attachable if one is present. ^Parameter^Value^Description^ |dispose| |Dispose of attachable after detaching it| This is an example of using this action: ===== attachSlot.check ===== Check one or more attach slot parameters. Action succeeds if all parameter value matches their respective attach slot parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a attach slot parameter matches (or not). ^Parameter^Value^Description^ |empty|''true'', ''false''|Attach slot is empty or not| |wait| |If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled| This is an example of using this action: false ====== Behavior Tree Conditions ====== This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''attachSlot'' with ''attachSlot(id)''. ===== attachSlot.check ===== Check one or more attach slot parameters. Conditions returns true if all parameter value match their respective attach slot parameter. This condition is typically used to run an action or sequence of actions as long as attach slot conditions are true. ^Parameter^Value^Description^ |attachSlot.empty|''true'', ''false''|Attach slot is empty or not| This is an example of using this condition: false attachSlot.check ====== State Machine Actions ====== Same as [[#behavior_tree_actions|Behavior Tree Actions]]. ====== State Machine Conditions ====== Same as [[#behavior_tree_conditions|Behavior Tree Conditions]]. ====== State Machine Events ====== This behavior sends these state machine events. If behavior has non-empty identifier replace ''attachSlot'' with ''attachSlot(id)''. ===== attachSlot.attached ===== Attachable has been attached to slot ===== attachSlot.detached ===== Attachable has been removed from slot. ====== Required Behaviors ====== This behavior requires no other behaviors. ====== Optional Behaviors ====== * [[behavior_collider|ECBehaviorCollider]] or [[behavior_vrhand|ECBehaviorVRHand]] * [[behavior_behaviortree|ECBehaviorBehaviorTree]]: Add actions and conditions for behavior trees to use. * [[behavior_statemachine|ECBehaviorStateMachine]]: Add actions and conditions for state machine to use and events to send to the state machine. ====== Persistency ====== This behavior does support element class to be persistable (setPersistable). ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorAttachSlot.html,ECBehaviorAttachSlot~@#. Since DragonScript Module Version ''1.0'' ====== Use Cases ====== * Add slots where elements supporting [[behavior_attachable|ECBehaviorAttachable]] can be attached to. ====== 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: right second second hand.attach.l ====== Live Examples ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]