Bolt. How to Listen to unity game events? What I'm doing wrong? is just me that needs this?

The problem:

I want to have bolt staying put and wait for an event to get fired by some other place in the game scene. Then when the event fired, bolt will do something.

I’ve tried searching the forum and internet, no luck in an answer.

What I’ve found is this asset

which does exactly what I’m asking except it doesn’t. Because the way it works is by manually tying in a script that send the event into the “On Unity Event” node.

So for each of these “On Unity Event” nodes you need a separate script tied in.

Boh.

If I need to write a custom script for all events that bolt needs to listen to I’m not doing any decoupling in the code.

I want bolt to listen to an event, defined by a simple string, the event name, and then do something.

I see waves of places where this “wait for event then do something” could be useful and now I’m puzzled because:

a. is a mistake what I’m trying to do? Have event fired and then bolt will do something is somehow wrong?

b. I can’t believe bolt is not able to do this. Maybe it can do it but I’m not able to find the answer. Must be something simple that I’m missing.

Doing this is documented here: Unity - Manual: Events under the section “Unity Events.”

I believe a better way to handle this is coming in a future release.

thank you, why it didn’t show your reply in my dashboard. I will check this

edit: well I need to create a custom bolt playboard or whatever for each of the events I want to send?

if I have 25 objects in the scene created at runtime do I need bolt attached to them? I don’t get it

Sorry for bringing up this old post - but I’d like to give some explanation.

So first of all: if you want to use the asset with the latest Unity-Version you have to update namespaces. First then it will compile again.

Then I don’t understand what you mean with “extra scripts”. Afair the asset was created at a time where unity wasn’t able to handle properly such code:

[SerializeField] private UnityEvent<string> onNameChanged;

You had to create a class inheriting UnityEvent and make it serilalizable. So at that time extra scripts where required. But this isn’t the case anymore.

If you go for AoT-Plattforms (like web/mobile). You have to use AotUnityEvents. And I THINK it should work fine if you just add the SerializeableAttribute to them:

using System;
using UnityEngine.Events;

namespace JFruit.Bolt {

    [Serializable]
    public class AotUnityEvent<T1> : UnityEvent<T1> {
        internal void Use() {
            new OnUnityEvent().OneParamHandler<T1>(null);
        }
    }
   
    [Serializable]
    public class AotUnityEvent<T1, T2> : UnityEvent<T1, T2> {
        internal void Use() {
            new OnUnityEvent().TwoParamsHandler<T1, T2>(null);
        }
    }
   
    [Serializable]
    public class AotUnityEvent<T1, T2, T3> : UnityEvent<T1, T2, T3> {
        internal void Use() {
            new OnUnityEvent().ThreeParamsHandler<T1, T2, T3>(null);
        }
    }
   
    [Serializable]
    public class AotUnityEvent<T1, T2, T3, T4> : UnityEvent<T1, T2, T3, T4> {
        internal void Use() {
            new OnUnityEvent().FourParamsHandler<T1, T2, T3, T4>(null);
        }
    }

}

Haven’t tried it out in real-world but I’m confident that then you also shouldn’t need any extra scripts. So you can use them like this:

[SerializableField] private AotUnityEvent<string> onNameChanged;

public AotUnityEvent<string> OnNameChanged => onNameChanged;

Therefor I don’t see where you would need any extra script.