I just saw this asset: Unity Asset Store - The Best Assets for Game Making which (if it does what it claims) breaks out of infinite loops. My suggestion is that Unity should buy this and put it into all versions of Unity. I think it would make Unity more appealing to learners.
It would be nice, especially since unity devs know how to do it, and even tell you. However Unity seems to have this underlying mindset of âits good enough, let assets do the restâ
Im guessing this is exactly what the asset is doing⌠Im sure you could easily replicate the asset based on the information provided in the link.
Or you could write good code.
And if thatâs not an option, hitting save before hitting play works too.
Edit: Donât mean to imply the tool isnât useful. If it can be integrated without degrading performance, Iâm all for it.
Actually, that asset looks pretty useful.
Sure, we can hand-wave it away as âonly noobs write infinite loopsâ, just donât forget that you donât always get to work with code thatâs completely your own. And heck, Iâve accidentally made an infinite loop on occasion, may as well get it fixed as quickly as possible when it happens. On that note, even if youâve saved your work it takes time to reopen the Editor and get back where you were, at which point you now have the joyful task of looking for that loopâŚ
Or you could press that button as soon as you realise whatâs happened, and immediately get a stack trace telling you exactly where it is.
(Note that I havenât tried myself, but Iâve been told that if youâre on Windows with VS you can just âAttach debuggerâ when youâve hit an infinite loop then pause the debugger for an almost identical effect.)
Well, nobody is perfect, even though I rarely use whiles. This is useful, indeed.
Sometimes itâs not just a while loop or even an infinite loop. Occasionally on a new system Iâll misjudge the processing time and set my game up to run at one frame per minute.
Breaking out of that would be convienient.
Except those times you forgot to hit save before play⌠cause im sure no one forgets to do thatâŚ
But then that goes right back to useful things unity SHOULD add, but leaves up to assets. Other examples auto-save scene/project every X minutes, autoSave on play, or prompt to save on playâŚ
The times I have locked up the editor, if i did not already have visual studio attached when the issue happened I was SOL, attempting to attach once âfrozenâ it just hangs trying to attach.
I bet if theyâd put this in Unity it would have got the biggest standing ovation of all of the Unity GDC keynotes.
Also, in Unity 2017 when they add visual scripting, allegedly, you donât want the artists to accidentally create an infinite loop and then lose all their work. (No offence to artists.)
I think a tool that points out infinite loops and tracks them down for you is a great thing. I can see how this would help a lot of people, but the truth is that if you find yourself writing a lot of infinite loops by accident, you need to reevaluate your code and the way you approach it.
@RuinsOfFeyrin -Unity actually does autosave to YourProject/Temp/__EditModeScene every time you hit play. lost data isnât much of a concern there.
Thereâs a responsibility when it comes to writing code because you are manipulating a device that doesnât belong to you. Your customers trust you to know what youâre doing when they run your code. Itâs important to reach a level of skill where you donât need a tool that points out loops, because you know what causes them and how to write code that doesnât have the possibility of looping infinitely. This is not requiring perfection- only practice.
Sometimes I forget to âyield return nullâ in âwhile(true)â loops in coroutines. And nobody remembers to save their project EVERY time they hit play. Especially if youâve been fiddling around in the scene a lot (e.g. UI elements) and then crash the editor itâs a real pain.
Unity should have this in by default, no question. If having a fail-safe makes people write lazy code more regularly, thatâs not my problem.
Erm⌠this is a Halting Problem. Which is unsolvable. Meaning such tool cannot exist.
Now, âemergency buttonâ that terminates execution even if the game is stuck in a loop is not bad, BUT there are already ways to deal with it (you can attach debugger and do some magic, or just terminate the process).
Iâm not sure why it is worht $10 or why it is worth adding to the engine. Looks like an âextremely beginnerâ kind of feature to me.
Why not just have a timeout that you can set in the settings?
Havenât done an infinite loop for a decade, and then a decade before then. Itâs nothing to do with being smart or not, itâs to do with just knowing the pitfalls and these are pretty easy to figure out. Usually it is something you just did.
Want to make it easier for newbies? Make visual scripting.
Are people really encountering this more than once every few years?
Not just infinite loops though, nothing more fun than accidentally putting a debug log on a function that runs every pixel in a 2k texture.
I think itâs a pretty basic thing actually, like having a spring on your car pedal. Just have a timeout on the frame so if it takes too long to get from one to the next, kick out to the editor.
Yeah see, that means Unity will end up adding more and more redundant checks (these checks do cost performance) for the sake of users who havenât even learned to drive the most basic car, for the most trivial problem ie grinding the gears.
Probably best to user an automatic ie visual scripting, which is coming.
Redundant checks for silly mistakes are worth it when you stand to lose a lot of work. I donât see why it would cost a lot of performance, framerate is already tracked. Itâs just a simple mechanism that improves usability.
You could say that itâs silly for a software to autosave every interval because it reduces performance. But who wants to worry about if theyâre going to remember to do some overhead task while theyâre trying to concentrate on something - it just adds mental baggage.
Also, problem has nothing to do with visual scripting, thatâs the equivalent of wrapping your entire body in bubblewrap just because you built the doorframe too low.
I think I made an accidentally infinite loop 3 times in past two years total.
However those kind of loops:
while(true){
.....
if (something)
break;
}
Are an extremely common thing in programming. But then again you probably already know that.
Now you have a point in the sense that logging system needs an update to handle massive amounts of text. Unreal 4 can easilly swallow terabytes of log messages per second without choking. Unity freezes instead.
However, iâd say that âinfinite loop protectionâ on its own is rather pointless. When your project is running, it is already saved on disk. So you can just kill the process for the same effect.
I think this analogy perfectly describes âinfinite loop panic buttonâ. When you do this kind of stuff in a normal programming, you kill the process. It is the usual thing.
I suppose so, although itâs rather cumbersome. Since weâre doing analogies, thatâs kind of like taking an ax to the drive belt of your engine to stop your car.
Maybe itâs somewhat ugly in theoretical terms, but then again most of the best ergonomics is ugly from a theoretical perspective. It certainly doesnât restrict anything else that you do or get in the way.
Funnily enough the windows graphics card timeout is way shorter than the time it would take for anyone to reasonably become upset, and itâs pretty annoying when you have some compute shader work to do, to have to split it all up.
Anyway, I think a crash timeout is just one of those simple things that makes life slightly better, and is going to have no negative impact on anything else that you do.
That stops the car though, doesnât it?
I have a Far Manager running in background, and killing a process is a matter of a few keypresses which can be done in a few seconds.
Basically, it is on the level âI want golden finish on my doorknob when my house is built! But only for one door on the second floor.â level. might be nice to have, but I donât exaclty see the pressing need for that. Either way it is for unity to decide.