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.

Resolved "For Loops" not working in build. (Saved Variables Mayham)

Discussion in 'Visual Scripting' started by Redhaired-Swordsman, Oct 19, 2022.

  1. Redhaired-Swordsman

    Redhaired-Swordsman

    Joined:
    Oct 11, 2021
    Posts:
    7
    Good day everybody, I have been working with bolt/Visual scripting for a while but now I have met an issue that I can´t figure out on my own.
    I got my game to run flawlessly without any errors within the editor but whenever I try to run the build it doesn't respond. I managed to figure out that the "for loops" are the issue here, every flow that includes said loop does not execute despite working within the editor.
    Is that a bug within the engine or is there an issue that I'm overlooking? I could theoretically rewrite the scripts without the "for loops" but that would make everything a lot more complicated and cluttered so I was hoping one of you wise people might help me out here.
     
  2. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    459
    The problem i have here, is that there's no information to go with. I dont use visual scripting, but maybe a few screenshots of the nodes, etc. ? GL.
     
  3. Redhaired-Swordsman

    Redhaired-Swordsman

    Joined:
    Oct 11, 2021
    Posts:
    7
    it is no issue with a specific line of code but any instance of the for loop. These graphs tend to get pretty convoluted with a lot of variables so it might be difficult to come to a conclusion, but here is one of the simpler ones. Here it is supposed to change the individual slots of the equipment list one by one when the player decides to change his equipment.
    upload_2022-10-19_17-56-42.png
     
    Homicide likes this.
  4. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    459
    Uhh, yea, i am definitely not the guy to help you with this one, as i mentioned i dont use Visual Scripting, and that image just gave me a giant hadache. I'm not sure how that is easier than a few lines of code on paper... But each to their own.

    Wish i could help more mate, but I dont even know where to start with that. GL.
     
  5. Redhaired-Swordsman

    Redhaired-Swordsman

    Joined:
    Oct 11, 2021
    Posts:
    7
    Yeah I totally get that, still thanks for trying though.
     
  6. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    Fyi
    The For Loop Node works for me after building.
    created a new project with this super simple graph and works in the build.
    must be an issue with the graph code.
    perhaps it is not being triggered or is turned off?

    built.PNG Capture.PNG
     
    Redhaired-Swordsman likes this.
  7. Redhaired-Swordsman

    Redhaired-Swordsman

    Joined:
    Oct 11, 2021
    Posts:
    7
    alright, this code actually does work, so it is not the "For loop" itself but the way Im using it. This realization gets me one step closer to the solution, thanks!
     
    REDACT3D_ likes this.
  8. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    I would probbly hook a bunch of Debug Log nodes around to make sure that you're getting the correct objects from your list and that the graph is actually running when you want it to.

    does it work in the editor when you use playmode?
    are you instantiating objects?
    are you referencing the right object / list?

    it appears like you're trying to set a saved list of string ID's for each weapon
    are you then saving the value? is it not saving? Telling it to save?
     
    Redhaired-Swordsman likes this.
  9. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    1,021
    My guess would be the saved variable. If it's set in some other graph without Save Variables node, it might be null. You could also check the Log file to see if any errors pop up at runtime or do a Debug build which will give you access to an in-game console for spotting errors.
     
    Redhaired-Swordsman likes this.
  10. Redhaired-Swordsman

    Redhaired-Swordsman

    Joined:
    Oct 11, 2021
    Posts:
    7
    Im almost there, thanks to the tip with the developer build I figured out that the index from the loop exceeds the length of my list of saved variables. Since the game works fine in the editor I figured theres an issue with the initial variables, but... there isnt. The initial and saved variables are identical, so unless they get altered in the build process they should not pose a problem. Thanks for bearing with me for so long, you guys have already helped me a lot.
     
    REDACT3D_ likes this.
  11. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    ah beauty.
    the ol' index starting at 0 while list counts at 1 thing

    did you get the out of range error as one would normally with that kind of error with index once you used the debug build?
     
  12. Redhaired-Swordsman

    Redhaired-Swordsman

    Joined:
    Oct 11, 2021
    Posts:
    7
    yes, as soon as I start the line of code the error appears, claiming the index is out of reach. Even if I change the first or the last number to adhere to any kind of counting method it still won´t work.
    And on top of all that the error does not show up when I test it inside the editor, so there shouldn't be anything wrong with the code to begin with. Somewhere in the building process something must get changed in order for that error to appear.
     
  13. Redhaired-Swordsman

    Redhaired-Swordsman

    Joined:
    Oct 11, 2021
    Posts:
    7
    Alright I figured it out. Despite what I assumed the initial saved variables do not exist in the build version. So I had to define them all within the code at the start of the game. Thanks Redact3d and Pantheneye, now I can finally go back to working on the game.
     
    REDACT3D_ likes this.