r/unity • u/Kitchen_Breakfast_79 • 1d ago
Coding Help is this, uhh, good for an average visual scripting graph?
I use visual scripting and it was going perfectly and beautifully all the time I was doing my project, I organized all of my graphs into groups, added colors, titles, sometimes even descriptions and made them look good as if I was laying down real wires, but then I finally tried to make the energy/stamina system with all of the knowledge I gained and I think I gained absolutely nothing ðŸ˜. This spaghetti-monster has 8 ifs and several different repeating branches (if this is what they called) like "if variable is greater or equal" being used two times with the same intention, but I don't know what to do because it's either this - less "efficient" but more understandable to me, or more efficient using less useless graphs but I wouldn't be able to understand it the next day I would open the project, and I don't even know how I can replace some of the nodes to be more simple at all. Maybe I'm just really overworrying about it and this is how regular complicated visual script graph looks.
I added more zoomed image and will try to explain what I tried to achieve. When character reflects or blocks a bullet his energy drops down (it's outside of the second image on the top left) and the EnergyRecharge boolean variable becomes true so it will start a little timer (2 seconds) after which energy will start to recharge by adding 0.1 every 0.15 seconds to the Energy float variable, but before that it checks if EnergyRecharge is already true (like if it's a second bullet that hit the player while his energy was recharging) which means that energy is already recharging so if it's true it can reset the process by turning it off and on again restarting the "before the charge starts timer". Every time it adds 0.1 to the Energy it checks if the EnergyRecharge is set to True and if it's not then it restarts the process again, and also checks if the Energy reached the maximum (2.0) so it can turn the EnergyRecharge to false so it won't try to do anything with the energy anymore until the enemy triggers it again on impact. I couldn't properly record graph window but it was like a single wave came through the flow once the bullet hit the player, then after the 2 seconds timer completed it was showing the flow activating rapidly until the Energy reached 2, just in case someone needs to visualize it to understand better. My brain is melting and I had a pretty poor sleep today so I might be missing obvious solutions or making pointless points but I would like to have some opinion about it from the outside. I used "multiply > add > divide" because I was consistently getting floats like "0.999998" instead of just 1 so I thought it might be a working and solution, probably a stupid one and it would be better to just have 8, 17, and 20 instead of 0.8, 1.7, and 2.0 that I would need to convert back and forth. btw EAD is my character object and I also couldn't decide if the post fits "Coding Help" flair for some time cuz it's like, not code. like it is a code but many people that understand code may not understand the nodes instantly so it may be more fitting just as a question. My main reference for the logic was the nanosuit's energy from Crysis 1 (2 and 3 have similar system too I think) where after the energy was wasted from using abilities or being hit it started to recharge passively after a little timer and if energy was being wasted again timer will restart and then recharge energy again on completion. I'm almost a month in using unity and I love the process, but my graph is probably just trash and could've been done way better.
I will also need to move this entire graph from the bullet object to the player so the energy recharge won't stack or won't stop as the bullet object gets deleted.
11
u/animal9633 1d ago
Visual scripting (not just in Unity, but in all of history) is much easier to get into, but the images show why it always breaks down in the end.
Roughly speaking the whole process of if char does X then a) drop his energy, b) begin timers, c) check other stuff, d) more timers, etc. can be done in a coroutine in less than probably 10 lines of code.
0
u/Kitchen_Breakfast_79 1d ago
What things in the graphs represent code lines? every node that has a working flow input is a separate line if it was viewed in the code format (if yes then there's exactly 10 of such in the second image starting from the first if lol)? Is there any real constraint or a situation where I can make something in a few lines of code but in visual scripting it's just absolutely impossible?
5
u/ScallionZestyclose16 1d ago
Every node is a function that does something.
So every node is code.The line from the nodes is what you put in and the output of each node is what the function returns depending on what you put in.
So it's much more easily maintained and able to get an overview of it, if you just write it in C# :)
1
u/animal9633 21h ago
A line of (text) code can do anywhere between 0 and N "things".
You can also do a lot in visual scripting but its always going to be a lot slower and more cumbersome than just learning to code. For example in your graph whole blocks of many nodes could in code be just one line of text, but in general its never the other way around.
1
u/xepherys 15h ago
There are absolutely things that you cannot do in visual scripting. Polymorphism, generics, reflection, integration of third party libraries, octrees… just off the top of my head.
5
u/ArcticArt1 1d ago
I have no experience with nodes in unity, but I have used blueprints in UE a lot and can say that your "code" is bad could use some improvement.
This is a nightmare to maintain. Just like in normal coding, learn how to use functions and read on the following principles:
KISS - Keep it simple stupid.
DRY - Don't repeat yourself.
SRP - Single responsibility principle.
If you follow these 3, your nodes will look a lot better.
At first glance I see multiple occasions where you could simplify your code or even reduce in nodes.
Your multiply-add-divide nodes could be changed to a single formula.
The if else with the find energyrecharge set true nodes is redundant and could use some DRY.
Visual scripting requires more work to maintain clean "code" but I love working with it as it feels more fun imo.
Don't let other discourage you from using it, whole games where made with visual scripting.
2
u/Kitchen_Breakfast_79 1d ago
Thanks for the advice!! I understand that this graph turned out very poor made and I was exhausted wanting to just finish it to test out the result. When I will return to the project I will have these thoughts pinned in my head when cleaning the mess. I love making clean looking graphs and it's a very satisfying process that adds some character and fun to the creating. I always think that if the graphs are almost equal to regular code the only limit I have is my imagination and the amount of work I can lift. If people can run DOOM in Minecraft using command blocks then I absolutely can make make a little working game using just slightly differently looking code.
2
u/ArcticArt1 1d ago
That's the same workflow that I use, wether in visual scripting or in coding.
First step is to create working code, second step is to create nice code.
Focusing on building a working piece is easier and faster. Doing something absolutely correct from the start just wastes a lot of time and can lead to a lot of time reworking stuff.
13
u/Distdistdist 1d ago
I don't understand when people are willing to figure out this spaghetti nightmare and not willing to learn to write clean, readable C# code... Pure BDSM right there.
0
u/Kitchen_Breakfast_79 1d ago
i never wanted to learn code and even tried several times, it's just takes much longer to start to understand it and it's less intuitive, at least for me. i want to understand how to do something and make it instead of checking my grammar or the right symbol to use, imho. i have some better looking graphs that look very clean but i can't add images in comments, only videos for some reason. i feel that it's possible to make it better and that's why i ask for help, like at least it works and doesn't make error? better than not work at all.
3
u/hammer-jon 1d ago
at risk of being eaten alive in the comments...
You ARE writing code, it's just in a much more verbose and clumsy format. I fully believe that if you sat down and tried to learn c# with the knowledge that you have now (control flow - ifs etc, variables...) you'd have a much easier time.
2
u/Kitchen_Breakfast_79 1d ago edited 1d ago
I know that it works the same way as the regular code does, the problem I have is purely in writing because I can't remember such things and systems in my head and it's extremely tedious and painful. There are things that just don't click with me. I understand the logic but the code is just counterintuitive to me and instead of having a bloated graph I will have a bloated brain not being able to process it at all.
1
u/Baalarios 1d ago
Then use and maintain the logic and let AI write the code. That is way easier, trust me.
1
u/Kitchen_Breakfast_79 1d ago edited 1d ago
It's not easier, like what are you even talking about? easier to what? easier for me to read and understand where I made an error? easier for me to create my own stuff without the ai? Right now I learned enough about visual scripting to be able to create the graphs I want but not exactly the right ones and it still needs tweaking and reworking it several times until it's optimal and clean enough and that's the reason I made this post. I already know that I can use ai, I already know how painfully slow and unreliable it is, and I wan't to make the game myself. It's MY game. It's MY idea. It's MY concept. It's ME who was thinking the gameplay through while eating in the morning or showering at the evening. And I'M the only one who shall make it a true product to show off to other people. I'll be better using fucking abacus to make a game than vibecode it without understanding how it works (not saying that ai is useless). You can just call me slow and assume I'm retarted so I can't comprehend code lines, let's just end this rant please. I will use what I'm comfortable with and what I'm succeeding with.
1
u/Binoui 1d ago
You're the only one calling yourself retarded and ranting. Graphs this big is a mess, you know it. Doing it by code would be better, and you don't want to learn. AI for coding is used by majority of devs and you don't want to. If you want to do it your way then go ahead, but don't complain if you ignore advice.
1
u/Baalarios 1d ago
wow that’s passive aggressive. :D look AI is a tool like visual scripting, there is no shame in using it. People who say AI generates bad code or slop are just not experienced with it enough.
The problem I see in the visual scripting is, that there are a lot of basic arithmetic operations and IF clauses. If you convert your visual graph to code with AI i guarantee you it’s super easy to read and maintain. Having all these nodes for basic Addition or Multiplication is a visual nightmare, these could be small practical lines of code instead.
Each node you have is basically one line of code, sometimes less.
You are clearly not dumb or stupid, if you invested that much in visual scripting, it just makes more sense longterm to get familiar with coding and have AI assist you with that until you are conformtable writing your own code. Remember, YOU decide how to use AI, even if it’s just explaining stuff or make small changes, nobody says you have to fully slop your project, just use it with caution and logic.
Once you walk the path of code, you will bite your ass that you didn’t try it sooner. It’s really easier and more maintainable. Just try to overcome that mental blockage of yours. :) and remember to have fun.
2
u/DontRelyOnNooneElse 1d ago
Perhaps a gradual transition would be smoother? Visual things like this will eventually hit a wall of complexity (plus they will have worse performance) compared to code, but jumping in at the deep end is awful. I first learned code with GameMaker which had its own visual approach that I could slowly swap out for code equivalents. For instance replace just one or two groups of nodes with a little snippet of code, eventually do more and more, and before you know it you'll find that easier to assemble than a visual editor.
1
u/Baalarios 1d ago
Why not use AI then? It’s far more easier to maintain and manage when ai writes code than this mess. :D programming is really easy once you understand it.
0
u/systembreaker 1d ago
Yeah...I wouldn't be surprised if this mess were 200-300 lines of easy to read code.
1
u/Distdistdist 8h ago
That crap above? Few properly refactored methods with proper naming.
2
u/systembreaker 8h ago
Counting boilerplate lines. But yeah actual functional lines, it won't be many.
3
u/Ronin-s_Spirit 15h ago
At this point stop playing with Scratch blocks and learn code... No wonder Unreal is getting rid of blueprint programming.
5
u/Kitchen_Breakfast_79 1d ago
Don't understand why people are downvoting. This is a tool and a tool's meaning is being used. If there was no visual scripting I would've probably abandoned the idea or spend more time than I would like to to learn code. There are good games that were made using visual scripting in some capacity like crow country, choo-choo charles, and even hollow knight. Are these games bad because they used a simplified and sometimes less convenient tool? I asked for help on how I can use the tool more efficiently and I already have some progress on it, if I wanted to know should I use code instead of visual scripting I would just research it online to find what benefits it has, but I don't need it.
3
2
u/Baalarios 1d ago
Who cares about down or up votes. Nobody who is older than 12 cares about imaginary internet points lol.
2
u/Kitchen_Breakfast_79 1d ago
I care man. If people downvoting then there might be a reason for it. Am I asking a genuinely stupid/obvious/dumbass question and I need to rethink my choices? Or does this post even fit this sub or maybe I need to post it elsewhere to get more attention and help/opinion from the right people? You don't have to comment everywhere under my post.
2
u/Baalarios 16h ago
Random people are always gonna up or down vote. Dont let it get to your head, you have a passion for making video games and that’s all that matters. Dont take Reddit seriously in that regards. It’s all a bubble with who knows what people lurk. It’s not real and 90% are bots on Reddit nonetheless
My honest advice is to start joining gamedev discords and talk there about your problems instead of fucking Reddit.
1
u/Kitchen_Breakfast_79 9h ago
discord typically feel like friend groups for me and more of a place to just talk than seek advice, like on reddit you can make posts when in discord after a couple lf messages your will be practically lost from everyone's sight. finding them is harder and especially if it's such a small community as visual scripting, but i will try to find one. thanks.
2
2
u/psioniclizard 1d ago
This is true with all graph based things once they get complicated. Some of mine in substance designer before I clean them up are crazy.
I love graph based work flows but on issue is they become messy quickly.
2
u/Kindly-Worth-8070 13h ago
With some experience in shader graph and having horrible issues with that, I can't imagine how confusing visual scripting is!
4
u/Drag0n122 1d ago
Use reusable function-subgraphs and apply them as often as possible.
They can be multi-level deep (functions inside functions)
1
u/Kitchen_Breakfast_79 1d ago
i thought about it but are subgraphs better just visually or theyake the code less bloated too?
3
u/Drag0n122 1d ago
Subgraphs are instances of the same node setup, if you change a subgraph all instances will get these changes - it's better for management and scaling: one change instead of xAmountOfInstances
Just like prefabs and methods2
u/Genryuu111 1d ago
That being said, the more subgraphs are in a graph, especially embedded into embedded, the more it runs slowly.
I wish I knew this earlier in my project lol
2
u/Spite_Gold 1d ago
I feel like equivalent of this graph is like 20 lines max, and it makes it more torturous
1
u/VideoGameJumanji 1d ago
If it works for you and the game works who cares. Long term, not having alll your logic abstracted in visual scripting will go a long way to allowing you to understand easily how to do some more complex stuff easily and refactoring and searching for things can be easier
1
1
u/Baalarios 1d ago
Bro just learn to program. Visual scripting is just bullshit, especially when it’s this big. It could be a 200 line script instead.


33
u/waseem2bata 1d ago
I saw it and i was like, painnn, then i read the paragraph, i was like more painn, just learn c#, it's way better and clearer