Treetrunk
Module: treetrunk.lua
Overview
The Treetrunk module is a small set-dressing script: when a tree trunk enters a fire state ("FireDebrisState" or "FireDestroyedState"), it plays a material animation on the trunk to show the charred/debris look. Thatβs the whole module β two functions, one deferred animation.
This is nearly identical to its sibling treetrunkpalm; the only real differences are the animation name (global_env_treeplaza03_anim here vs. global_env_treepalm_anim) and that the palm version also prints a debug line. See βModule constantsβ below.
Inheritance
- Inherits from:
none(base/utility module) - Imports: none. (
String,Event,Objectare built-in engine namespaces called directly, notimport()ed modules β this file has noimport(...)orinherit(...)calls at all.)
Instance pattern
This is a stateless utility module. It does not track any per-instance state; instead, it handles global events related to tree trunk states.
Functions
OnStateChange(uiGuid, uiNodeHashName, uiStateHashName)
Engine lifecycle callback. Compares uiStateHashName against String.GetHash("FireDebrisState") and String.GetHash("FireDestroyedState") (i.e. it hashes the state name strings and compares hashes, rather than converting the incoming hash to a string). On a match it schedules _PlayMaterialAnims via Event.ObjectIsReady. uiNodeHashName is unused.
_PlayMaterialAnims(uiGuid)
Calls Object.PlayMaterialAnimation(uiGuid, "global_env_treeplaza03_anim", false) β the trailing false means non-looping (play once).
Events
Event.ObjectIsReady(inOnStateChange, viaEvent.Create) β the onlyEvent.*call in this file. Used to defer_PlayMaterialAnimsuntil the object is ready, after a matching state change is detected.OnStateChangeitself is not registered throughEvent.Createin this file β noEvent.ObjectStateChange(or similarly named constant) appears anywhere in the source. Itβs invoked directly by the engine as a naming-convention callback on the world-object script, the same wayOnActivate/OnDeathare called on other modules.
Module constants & tunables
- Trigger states:
"FireDebrisState"and"FireDestroyedState"(compared as hashes viaString.GetHash). These are the authored object states that fire the animation. - Material animation:
"global_env_treeplaza03_anim", played once (non-looping).
Notes for modders
- Change the animation by editing the
"global_env_treeplaza03_anim"string in_PlayMaterialAnims; change when it plays by editing the two state names inOnStateChange. - The animation is deliberately deferred with
Event.ObjectIsReadyβ the object may not be ready to animate at the instant its state changes, so donβt callObject.PlayMaterialAnimationdirectly fromOnStateChange.