Hi I’m following the documentation of Declare a custom event type : Script Examples | Needle Engine Documentation
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 ` :

[Original Post on Discord](https://discord.com/channels/717429793926283276/1167634515972337684)
*by user 632418299711324161*
If I delete this line from CustomEventCaller
: //@type MyCustomUnityEvent
, then it looks like this :

by user 632418299711324161
But when I Invoke
the method, nothing happens
by user 632418299711324161
Do you know what could be happening ?
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.
by user 632418299711324161
Can you show an example where you have added a method to the event?
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 :
export class CustomEventReceiver extends Behaviour {
logStringAndObject(str: string) {
console.log("From Event: "+str);
}
}
*by user 632418299711324161*
This is how the sphere looks in Unity :
by user 632418299711324161
This is the console’s log :
by user 632418299711324161
So it seems that the event actually is beeing invoking but not with the argument of “Hello” which I’m passing in CustomEventCaller
.
by user 632418299711324161
Otherwise if I write directly in Unity the argument for the method logStringAndObject
, like this :

by user 632418299711324161
by user 632418299711324161
This is my log.
by user 632418299711324161
But I want the argument to be passed from the script CustomEventCaller
, Do you know what could be wrong ? Thanks 
by user 632418299711324161
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
Okey, thanks again marcel : )
by user 632418299711324161