Hotspot script bug : start() on EventListening


I use Hotspot in my scene that I add dynamically, my hotspot manager and hotspot template are already in my scene before my hotspot generation.
And it works well, except for a detail :

I added a small function to add dynamically differents function to a button, like it :
addFunctionOnClick(element, functionToAdd) {
In Hotspot.ts

But if I call this function, when I will click on my button on my hotspot it will launch it start() function (which is pretty weird)

I initialize my hotspot like it :

const scalarDirection = direction.clone().multiplyScalar(-20).add(vector);
    // const advancedPosition = new THREE.Vector3().copy(position3D);
    const positionline = new THREE.Vector3().add(scalarDirection);

    const hotspotObject = new Object3D()
    const hotSpotComp = new Hotspot()
    GameObject.addComponent(hotspotObject, hotSpotComp)



    const timer = setTimeout(() => {
      // hotSpotTest.hotspot?.setContentText(text)
      // Here the main problem
      hotSpotComp.hotspot?.addFunctionOnClick(hotSpotComp.hotspot.deletebutton, () => this.toDistance(0.5))
      hotSpotComp.hotspot?.addFunctionOnClick(hotSpotComp.hotspot.plusbutton, () => this.adjustDistance(true))
      hotSpotComp.hotspot?.addFunctionOnClick(hotSpotComp.hotspot.minusbutton, () => this.adjustDistance(false))
    }, 500)

Did somebody has an idea ?

Original Post on Discord

by user 224464722878005248

What do you mean by this?
But if I call this function, when I will click on my button on my hotspot it will launch it start() function (which is pretty weird) ?

I got a + button for example
If I let it without calling hotSpotComp.hotspot?.addFunctionOnClick(hotSpotComp.hotspot.plusbutton, () => this.adjustDistance(true))
There is no effect, just the button color animation by default
If I call hotSpotComp.hotspot?.addFunctionOnClick(hotSpotComp.hotspot.plusbutton, () => this.adjustDistance(true))
To add the this.adjustDistance function when I click on the button, this.adjustDistance is called which is fine

But the start() function of the hotspot too !
This one :

// TODO figure out why onEnable doesn't work here
    start() {
        console.log("Hotspot start")
        // instantiate a hotspot here
        const options = new InstantiateOptions();
        options.parent = this.gameObject;
        this.instance = GameObject.instantiate(HotspotManager.Instance.hotspotTemplate.gameObject, options);
        if(!this.instance) console.error("No hotspot template assigned to HotspotManager!")
        else {
            this.hotspot = this.instance?.getComponent(HotspotBehaviour);
            if (this.hotspot) {
                GameObject.setActive(this.hotspot.gameObject, true);

by user 224464722878005248

I found the solution

by user 224464722878005248

It’s an error from my side, sorry for bothering you

by user 224464722878005248

It’s an external verification which recall the initiation of a new hotspot which create this error

by user 224464722878005248

Ok. What you also could probably do is to assign a new EventList to the button that has your methods inside
button.onClick = new EventList([eventMethod1, eventMethod2])

Okay I will test

by user 224464722878005248