I’m trying out C# events to realize a click to point movement of my avatar. Using the basic generic events in NodeCanvas works like a charm. But now I just stumbled upon a problem with generic Events if I try to send/recive events with multiple parameters. Is this possible?
My mouse handler actually send an event with two parameters: the vector3 target position and an acceleration float value. Both are required by the BT to handle the seek and animation actions when the event has been notified. The acceleration value could be 0.5f for walk and 1 for running (on double click) used by Mechanim for blending.
How could I archive this? Or should I use a differend approach?
Thanks in advance for any help.
Unfortunately right now, only one parameter is possible for events. The reason behind this was performance and to avoid boxing by using generics, but on the other I couldn’t use more than one generic argument due to having those generics possible to also work on AOT.
Probably the best solution at the moment, would be to create a simple struct that includes all parameters you need, and have your event send that as a single parameter. It’s really not the best solution though, and this is the reason I am looking at improving events to support more than one argument.
Just to clarify though, are you talking about “Check Custom Event”, or “Script Control/Check CSharpEvent”?
thanks for your response. Actually I solved this by using a backboard variable setting for the movement parameter as workaround. However I will give your hint with the struct as event object a try to decouple my controller from the behavior tree.
I use a Utility/Check Event to catch the events. I could not get the Check CSharpEvent working, any entry on Select Event is disabled and I found no documentation or example how I have to use it correctly.
Thanks for the follow up.
Regarding “CheckCSharpEvent”, it only works with events of delegate type System.Action or System.Action<T>. The entries in the menu being disabled, means that none of the types in the PreferredTypes List (which is shown in the menu), has any public event System.Action.
If for example though, you create a class like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
publicclassMyExampleType:MonoBehaviour{
publicevent System.Action onEvent;
voidUpdate(){
if(Input.GetKeyDown(KeyCode.Space)){
if(onEvent!=null){
onEvent();
}
}
}
}
..and then add this “MyExampleType” in the PreferredTypes List, you will be able to see and select “MyExampleType.onEvent”, in the “CheckCSharpEvent” selection menu.
Let me know if you need any further clarification with this 🙂
Thank you.
thanks a lot for your hints and explanations. This clarify all, actually I use only UnityEvents at my controllers.
I will test your example to decouple the controller from explicitly BT calls.