Search Unity

Call custom event on specific state machine

Discussion in 'Visual Scripting' started by erikorban-unity, Sep 13, 2022.

  1. erikorban-unity

    erikorban-unity

    Joined:
    Feb 9, 2021
    Posts:
    3
    Hi all,

    I am kinda new to the visual scripting and I was wondering how can I call a custom event in a state machine. By calling the EventBus.Trigger function I was only able to invoke all the occurences, not specified to one instance.

    My state machine is fairly simple, as you can see at screenshot below.

    FYI: The Random Event Caller is triggering all the occurences, but I also want to trigger a specific one with a script. I tried to make something with GameObjectEventUnit, but I simply failed. I got no examples for that.

    Thank you in advance!
     

    Attached Files:

  2. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    the tigger custom event will trigger once when the event is called inside the object it's attached to, otherwise you just plug it into the object that you want to reference. if i'm understanding the issue

    thing.PNG f1.PNG f2.PNG
     
    erikorban-unity likes this.
  3. erikorban-unity

    erikorban-unity

    Joined:
    Feb 9, 2021
    Posts:
    3
    Thank you for your answer, I tried out all of them, but my issue is still persists. Probably my explanation was not clarified enough, sorry for that.

    My scenario is:
    - I have two gameobjects in the scene: GO 1 and GO 2 (both has a script machine attached and both has the same graph).
    - I want to create a custom event (with code) and than trigger that event (with code) based on a business logic.
    - Lets say I want to trigger the custom event in the GO 1 object's graph, but only there, the other occuerences are untouched
    - But some time later I also want to trigger only the GO 2 object's graph, but now exclusively on that instance

    So my question is, can I trigger an event only in one occurence of the graph, on a specified instance?
     
  4. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    Oh okay I think I understand.
    I believe that all you need to do is use Variables that reference the "Object" instead of "graph"

    Inside the graph editor, on the left hand blackboard, you can see the variables window.
    1.PNG

    The values stored in the OBJECT tab are associated with that instance of the object. basically meaning that each copy will have it's own values. For example, a position or maybe heath.

    If GRAPH values are used, those values are shared among all instances.
    So for example, change one thing and it changes in all copies. Not what you're lookin for.


    You can see the variables as a Component on the Gameobject right hand side.
    2.PNG

    Make sure you have the actual object selected when setting you values inside the Object tab.
    it is possible to have the wrong thing selected, and you edit the wrong script lol


    I THINK all you need to do is use object variables here
     
  5. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    oh, and you just GET or SET the values by selecting Object on the dropdown

    This example will add 1 to the value every update.



    s.PNG