1 - I have added this C# script to the Needle/Components.codegen file :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
[System.Serializable]
public class MyCustomUnityEvent : MonoBehaviour
{
}
2- Then I copy-pasted both classes from the documentation
// The next line is not just a comment, it defines
// a specific type for the component generator to use.
//@type MyCustomUnityEvent
@serializable(EventList)
myEvent!: EventList;
// just for testing - could be when a button is clicked, etc.
start() {
this.myEvent.invoke("Hello");
}
}
export class CustomEventReceiver extends Behaviour {
logStringAndObject(str: string) {
console.log("From Event: ", str);
}
}```
3- But when I add both scripts to an GameObject , the field of `myEvent` from `CustomEventCaller ` looks like this and I cannot add the the reference of `CustomEventReceiver ` :
![image.png](https://cdn.discordapp.com/attachments/1167634515972337684/1167634516140105829/image.png?ex=65d944e2&is=65c6cfe2&hm=84399892e60aa2fa2cd87078d08b459dfa7d57a7b6f04b2e3ccc09a324813b3c&)
[Original Post on Discord](https://discord.com/channels/717429793926283276/1167634515972337684)
*by user 632418299711324161*
If you do not have any methods/listeners added to your event list / unity event then nothing will happen if you call invoke
Click the plus button in the MyEvent list in unity and add a method to be called when you invoke your Event. What you have been building here is a flexible way to connect events in the unity editor you just need to make the connections now and it will work
That´s the problem, if I add a method to the MyEventList nothing happens in this case. I follow each step in the documentation but it doesn´t work. Could you give a brief explanation of each step to call a custom event ? Maybe there is something I am losing.
Srry for no answer but I made another example and it works almost fine. This is my example :
I have a Sphere with two scripts :
The first one :
// The next line is not just a comment, it defines
// a specific type for the component generator to use.
@serializable(EventList)
myEvent!: EventList;
update(): void {
if(this.context.input.getKeyDown()=='a'){
this.myEvent.invoke("Hello");
}
}
}```
The second one :
When you save this script again the component generator will create UnityEvent without the argument - which seems to be what you actually want. If you have a string argument serialized in Unity that’s what will be used to invoke the event