Hi,
I have a custom script added to the Actor game object with a public method, something like
public void RunAction(GameObject go) {... do something}
I need this method to be called whenever some specific dialogue entry is played.
I tried to use OnExecute() but that event is very limited. I think I should use the lua script but I have no clue how to write such script, need some guidances, tks
Call custom script method from specific dialogue entry
Re: Call custom script method from specific dialogue entry
I'm thinking to use the SendMessage() is the right way, but since the actor has many custom comportment scripts, how do I specific which script's mehtod?
SendMessage(RunAction, goName)
or maybe
SendMessage(CustomScript.RunAction, goName) ?
SendMessage(RunAction, goName)
or maybe
SendMessage(CustomScript.RunAction, goName) ?
Re: Call custom script method from specific dialogue entry
Hi,
In version 2.2.6 and earlier, the usual way would be to use SendMessage() or write a custom sequencer command or register a C# methods as a Lua function.
However, with 2.2.7+, you can add a scene-based UnityEvent to a dialogue entry node. Then you can assign your scene object and call its script method.
In version 2.2.6 and earlier, the usual way would be to use SendMessage() or write a custom sequencer command or register a C# methods as a Lua function.
However, with 2.2.7+, you can add a scene-based UnityEvent to a dialogue entry node. Then you can assign your scene object and call its script method.
Re: Call custom script method from specific dialogue entry
Just updated to 2.2.7, right on time, lol
If I understand correctly (I see the change in the inspector for Add Scene Events), the OnExecute() becomes more flexible, is this what you have mentioned "Scene Based Unity Event"?
At least I'm able to drag the gameobject and call its method with parameters.
However, my issue is that the Game Object and the method's parameter (also a game object), both of them are instantiated in runtime, it is a clone of a prefab, is it still possible to assign it in the inspector? or I need to write a custom script to create the OnExecute() in runtime? if so, how do I add the OnExecute for a specific dialogue entry? tks
If I understand correctly (I see the change in the inspector for Add Scene Events), the OnExecute() becomes more flexible, is this what you have mentioned "Scene Based Unity Event"?
At least I'm able to drag the gameobject and call its method with parameters.
However, my issue is that the Game Object and the method's parameter (also a game object), both of them are instantiated in runtime, it is a clone of a prefab, is it still possible to assign it in the inspector? or I need to write a custom script to create the OnExecute() in runtime? if so, how do I add the OnExecute for a specific dialogue entry? tks
Re: Call custom script method from specific dialogue entry
You can write a custom script that accesses the cloned instance and calls the method on it. For example, if the prefab is instantiated by some kind of spawner script, that spawner script can retain a reference to the instance and call a method on it.
Then you'd hook up the dialogue entry node's OnExecute() event to the spawner, since it exists in the scene at design time.
Then you'd hook up the dialogue entry node's OnExecute() event to the spawner, since it exists in the scene at design time.
Re: Call custom script method from specific dialogue entry
Hi Tony, not quite sure I fully understand your solution.
Do you mean that I should add a game object to the Scene hierarchy, add a custom script to hold some variables? So whenever my prefabs got instantiated, it pass its reference to that game object.
Then in the dialogue entry inspector, I add that game object and its custom script method to the OnExecute event?
thanks
Do you mean that I should add a game object to the Scene hierarchy, add a custom script to hold some variables? So whenever my prefabs got instantiated, it pass its reference to that game object.
Then in the dialogue entry inspector, I add that game object and its custom script method to the OnExecute event?
thanks
Re: Call custom script method from specific dialogue entry
Yes. What instantiates the prefab in the first place?
Re: Call custom script method from specific dialogue entry
it works, haha, the in scene event rocks!!! tks for the update Tony
Re: Call custom script method from specific dialogue entry
Glad to help! That's been a big request for a while. I think it's going to really open up possibilities for people.