Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Why is my Flow Graph not Behaving as Expected?

Discussion in 'Visual Scripting' started by Ecliptec_Mobile, Nov 16, 2022.

  1. Ecliptec_Mobile


    Dec 17, 2017
    I've created an initial set up for a designer to implement quest objectives using Visual Scripting. In the image you can see the flow of what I'm triyng to achieve.

    1. On Start, I create a PrefabRef node (custom-defined struct) which takes in a string Id (1).
    2. A list is created with this PrefabRef node and is passed in to the creation of KillCountObjective (custom-defined struct).
    3. The KillCountObjective is passed (with a single PrefabRef node) is added to a list (of objectives).
    4. On Update event, I query for input (in this case numbers 1/2/3 on the keypad).
    5. If Numpad 1 is pressed, I invole a method 'HandleNpcKilled' (which is a method on KillCountObjective) passing in some ids (in this case 1 to match that of the original list).
    6. The HandleNpcKilled method attempts to find and remove a PrefabRef node with the given id (this case 1).
    7. After HandleNpcKilled invocation, the next step in the Flow is a Custom Event Trigger (OnEvaluateObjectives). This event is triggered and invokes Evaluate on all conditions in the list. Evaluate is an interface method which all ObjectiveConditions must implement (there can be many type of ObjectiveCondition but I am just using KillCount as a test. The Evalaute method returns true on KillCountObjective if it's PrefabRef node list is empty. (in this case I am creating the list on Start and removing via key press to test).

    Screenshot 2022-11-16 110422.png

    There is some behaviour going on here which I can't fathom. I confirm that the initial list is created on Start with the appopriate PrefabRef node list with asingle item (id = 1).

    Whenever I press the numberpad 1 key to trigger the removal of this item, a whole new KillCountCondition is constructed (as if it's a new instance) in the Flow and it seems the Evaluate method is called on the [new instance] but the item is removed from the original instance (or so it seems). This means the Evalaute function returns false becuase it's PrefNode list is empty.

    Can someone suggest what's wrong here? Why does pressing 1 onthe num keypad trigger a whole new creation of the KillCountCondition and not pas the event to the [correct instance] (created on Start).