Search Unity

Unity Visual Script Show Different Values for 1 Boolean value

Discussion in 'Visual Scripting' started by Eatsuki, Oct 14, 2021.

  1. Eatsuki

    Eatsuki

    Joined:
    Jun 4, 2021
    Posts:
    25
    I'm working on a project and checking some values for it. In some case my code start to not working properly, so when i checked it with debug log, its shows different value for one boolean value. Debug log gets it correct but select component gets wrong value like show in picture. How can i fix it?
     

    Attached Files:

  2. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,075
    When you request the output of a value multiple times, it's reevaluated for each request. UnityVS doesn't automatically cache values for you.

    Try setting a boolean flow or graph variable and then use the value of that for both bool inputs.
     
  3. Eatsuki

    Eatsuki

    Joined:
    Jun 4, 2021
    Posts:
    25
    It's interesting. I set graph variables for all multiple outputs and it's seem working normal. I have one last question: It redo work for each request and probably random value being problem for my situation. so if set multiple outputs for that doesnt have random or getting time stuff, does it work fine?
     
  4. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,075
    You might still get unexpected results since the value you're requesting can change between requests even if it does not include random.range. Some logic elsewhere in the graph or another graph entirely could be changing one of the requested values.

    If you're requesting the same value multiple times in your flow, a good practice would be to use variables or the "cache" node.