Is there a way I can run a function after a node is complete?
I want to enable a function that enables a script once it's reached the end of that node(Which is also the end of the conversation).
Re: Activate function after specific Node
Posted: Thu Mar 10, 2022 7:59 am
by Tony Li
Hi,
If your function is a C# method, there are two common ways to activate it: as a Lua function in a node's Script field, or using a node's OnExecute() scene event. However, both of these ways run as soon as the node starts.
You could add an empty node to the end of your conversation. Activate the function in that node. Leave the Dialogue Text blank, and set the Sequence to: Continue()
If you can't add an empty node for some reason, another option is to use a sequencer command. If you want to enable a script, you can even use the built-in SetEnabled() sequencer command. For example, say you want to enable a script named MyScript on a GameObject named MyGameObject. If you automatically advance each node based on the duration of the text, you could set the final node's Sequence to:
I was able to use the first approach, however, the gameobject doesn't seem to disable on the node I want it to. I believe this has to do with OnExecute() running the prefab gameobject rather than the gameobject in the scene. Is there a way to use a gameobject from a scene?
To provide some more context, I want the blue ghost to be disabled at the start and only turn on once the last node has run.
Ghost Movement.png (357.72 KiB) Viewed 721 times
I made a function that will do what I want and it DOES work, but it only works in the "Prefab" version of this. (Prefab being in the asset folder). Even if I drag the prefab onto the scene, this method does't run for the object I want it to
Re: Activate function after specific Node
Posted: Thu Mar 10, 2022 9:57 am
by soniclinkerman
Update
I seemed to get it working by connecting my C# scripts to Lua.
I used this video to help me out:
Thank you!
Re: Activate function after specific Node
Posted: Thu Mar 10, 2022 10:33 am
by Tony Li
Hi,
I'm glad you got it working.
You can also assign scene objects to OnExecute() events. See Scene-Based Events. This way, you could have assigned the scene instance of the ghost to the event.
Another option that I didn't mention before would be to add a Dialogue System Events to Enti. Configure its OnConversationEnd() event to activate the blue ghost.