Unity - please add this?

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.

9 Likes

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.

1 Like

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.)

5 Likes

Well, nobody is perfect, even though I rarely use whiles. This is useful, indeed.

1 Like

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.

2 Likes

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.

3 Likes

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.

1 Like

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.

3 Likes

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? :stuck_out_tongue:

2 Likes

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.

1 Like

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.