EventBus.Trigger not called MyCustomEvent

VS Package 1.6.1
Unity 2021.1.22

private void OnTriggerEnter(Collider other)
{
    var player = other.GetComponent<Player>();
    if (player)
    {
        EventBus.Trigger(EventNames.MyCustomEvent, gameObject, 2);
    }
}
using Unity.VisualScripting;
using UnityEngine;

//Registering a string name for your custom event to hook it to an event. You can save this class in a separated file and add multiple events to it as public static strings.
public static class EventNames
{
   public static string MyCustomEvent = "MyCustomEvent";
}

[UnitTitle("On my Custom Event")]//Custom EventUnit to receive the event. Adding On to the unit title as an event naming convention.
[UnitCategory("Events\\MyEvents")]//Setting the path to find the unit in the fuzzy finder in Events > My Events.
public class MyCustomEvent : EventUnit<int>
{
   [DoNotSerialize]// No need to serialize ports.
   public ValueOutput result { get; private set; }// The event output data to return when the event is triggered.
   protected override bool register => true;

   // Adding an EventHook with the name of the event to the list of visual scripting events.
   public override EventHook GetHook(GraphReference reference)
   {
       return new EventHook(EventNames.MyCustomEvent);
   }
   protected override void Definition()
   {
       base.Definition();
       // Setting the value on our port.
       result = ValueOutput<int>(nameof(result));
   }
   // Setting the value on our port.
   protected override void AssignArguments(Flow flow, int data)
   {
       flow.SetValue(result, data);
   }
}

Expected result: Trigger with second param (gameObject) called event only in gameObject script machine
Have result: Trigger not called MyCustomEvent if I set Target param.

EventBus.Trigger without second param works fine but Globally :frowning:

bump

It’s the issue or am I doing something wrong?

I’m pretty sure you should be switching EventUnit to GameObjectEventUnit. Not all event types expect a target. You can make events that use totally different information to determine how and when they get triggered.

Then you should add the base of AssignArguments to ensure the game object is being assigned.

Thanks, Bro.

GameObjectEventUnit is what I need.
It is a pity that an example with its use is not described in the documentation.

I don’t suppose either of you would like to drop a sample custom GameObjectEventUnit into the thread here?
In particular I’m not sure what MessageListenerType should be?
I’m trying to build a CustomEventNode but as per the OP, the event is never being recognised, and it looks like GetHook is never called to register the node.

I make custom VS event to Take damage from Player. For this you need Player, PlayerMessageListener, TakeDamageEvent classes

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class Player : MonoBehaviour
{
    // Start is called before the first frame update
    IEnumerator Start()
    {
        while (true)
        {
            yield return new WaitForSeconds(2);
            TakeDamage(10);
        }
    }

    public void TakeDamage(float amount)
    {
        EventBus.Trigger(EventNames.TakeDamageEvent, gameObject, amount);
    }
}
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

[UnityEngine.AddComponentMenu("")]
public class PlayerMessageListener : MessageListener
{
   
}
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public static class EventNames
{
    public static string TakeDamageEvent = "TakeDamageEvent";
}

[UnitTitle("Take Damage Event")]//Custom EventUnit to receive the event. Adding On to the unit title as an event naming convention.
[UnitCategory("Events\\MyEvents")]//Setting the path to find the unit in the fuzzy finder in Events > My Events.

public class TakeDamageEvent : GameObjectEventUnit<float>
{
    public override Type MessageListenerType => typeof(PlayerMessageListener);

    protected override string hookName => EventNames.TakeDamageEvent;
   
    [DoNotSerialize]// No need to serialize ports.
    public ValueOutput result { get; private set; }// The Event output data to return when the Event is triggered.

    protected override void Definition()
    {
        base.Definition();
        // Setting the value on our port.
        result = ValueOutput<float>(nameof(result));
    }

    protected override void AssignArguments(Flow flow, float args)
    {
        base.AssignArguments(flow, args);
        flow.SetValue(result, args);
    }
}

Only Player component and Script Machine added to the same GameObject

My Embed Script graph

Good luck

i try to call my custom event from my C# script but i get syntax Error

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class CodeTriggerCustomEvent : MonoBehaviour
{

    void Update()
    {
        if (Input.anyKeyDown)
        {
            //Trigger the previously created Custom Scripting Event MyCustomEvent with the integer value 2.
            EventBus.Trigger(EventNames.MyCustomEvent, 2);
        }
    }

This code from Unity documentation

My screenshot

What error message do you have?

i show it on my screenshot

Give me pls error message from Log window

Error is here. This is enough to make the code not work
Log clean.

Sorry
Log contains error message

8901795--1218060--Снимок экрана 2023-03-25 в 09.30.27.png

This code from Unity documentation
https://docs.unity3d.com/Packages/com.unity.visualscripting@1.7/manual/vs-create-own-custom-event-node-trigger-code.html

You are missing a close bracket here
8904891--1218744--upload_2023-3-26_23-12-48.png

Ok but it doesn’t fix the error.
The code still doesn’t work

8905371--1218903--Снимок экрана 2023-03-27 в 09.06.50.jpg

It’s another error. You are missing class name EventNames

8905596--1218939--upload_2023-3-27_11-5-41.png
You can add this class to your script or create a new script with the name and code that I show in the screen

Oh, but i get this code from Unity Documentation and there are no this actions

https://docs.unity3d.com/Packages/c…reate-own-custom-event-node-trigger-code.html

8905623--1218960--upload_2023-3-27_11-22-28.png

Ok, I started reading this article not at first. Thanks for helping me understand