User Tools

Site Tools


dragengine:modules:dragonscript:behavior_elements

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
dragengine:modules:dragonscript:behavior_elements [2025/03/13 23:15] – [XML Element Classes] dragonlorddragengine:modules:dragonscript:behavior_elements [2025/03/26 11:45] (current) – [Examples] dragonlord
Line 109: Line 109:
 Using unique instances allows to add run-time features to your class on top of what BehaviorElement provides without creating an own behavior. In general it is recommended to work with behaviors only and creating your own ones. This way you can reuse game logic across different projects easily. Using unique instances allows to add run-time features to your class on top of what BehaviorElement provides without creating an own behavior. In general it is recommended to work with behaviors only and creating your own ones. This way you can reuse game logic across different projects easily.
  
 +====== Attachable Behaviors ======
 +
 +Attachable behaviors allow to add temporary behaviors to an element at runtime. They are similar in how the work to regular behaviors but instead of being added to #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElementClass.html,BehaviorElementClass~@# they are added to #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElement.html,BehaviorElement~@# directly. Hence while all #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElement.html,BehaviorElement~@# belonging to the same #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElementClass.html,BehaviorElementClass~@# own the same behaviors they all can have individual attachable behaviors. Furthermore attachable behaviors can be removed which can not be done with regular behaviors.
 +
 +Attachable behaviors implement #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECAttachableBehavior.html,ECAttachableBehavior~@# or subclass #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1DefaultECAttachableBehavior.html,DefaultECAttachableBehavior~@#. At runtime script code can attach behaviors using BehaviorElement.addAttachableBehavior() as well as removing it any time using BehaviorElement.removeAttachableBehavior().
 +
 +Once added attachable behaviors can react to similar events like behaviors if they request it. Usually attachable behaviors react to onAddToElement() and onRemoveFromElement() to add or remove their effect to the parent element. 
 +
 +Attachable behaviors also are required to be persistable the same way as behaviors are. Hence attachable behaviors added to behavior elements are persisted in a future proof way as regular behaviors are.
 +
 +Important to note is that attachable behaviors do not use the same interface as regular behaviors. This is on purpose since regular behaviors are split into ECBehavior and ECBehaviorInstance working together while ECAttachableBehavior is a standalone instance.
 ====== XML Element Classes ====== ====== XML Element Classes ======
  
dragengine/modules/dragonscript/behavior_elements.txt · Last modified: 2025/03/26 11:45 by dragonlord