Custom Event Handlers
Using events in custom MonoBehaviours
When the Animated Text Events component is not good enough or too inconvenient to use, you may want to register your own event listeners. After reading this short guide, I recommend looking at the code of the built-in event handlers and the Example Dialogue component, from the example scene, for inspiration.
To get started, your component needs a reference to the UI Document containing your animated text element.
Then you can use
TextAnimationUtility.GetAnimatedTextElement
to find your text element. If you need a specific type of animated text element instead of the interfaceIAnimatedTextElement
, useuiDocument.rootVisualElement.Q<AnimatedLabel>("dialogue-box")
instead.Register handlers for the events you're interested in.
Make sure to unregister all events in
OnDisable
, or your component will continue working when disabled.
Are you stuck? Maybe you need another kind of event that isn't supported yet?
Contact me via the contact form, or join my Discord and I'll try my best to help you!
Last updated
Was this helpful?