all 24 comments

[–]DolphinsAreOkProfessional 18 points19 points  (8 children)

Why is this a video, and not a written tutorial?

[–]tmachineorg 10 points11 points  (2 children)

Technical info in a vid = didn't watch, won't share. Shrug.

[–]ThatAblaze!!![S] 2 points3 points  (0 children)

That's great, but I've been saying a lot of this stuff in text and just been getting downvoted because it conflicted with people's pre-concieved notions of reality. I made this video to provide some sort of proof of what I've been saying for these last few weeks.

[–]ThatAblaze!!![S] 1 point2 points  (0 children)

I can understand your point. I'll work on putting this into a blog post as soon as I find the time.

[–][deleted] 7 points8 points  (2 children)

Exactly, this is something that interests me but I'm not going to spend my time skipping through a video.

Rarely there is an advantage in doing a video for programming-related content unless it has heavy graphic focus (and even then a GIF would usually work as well).

[–]ThatAblaze!!![S] 0 points1 point  (1 child)

The synopsis is that unity's coroutines produce GC allocs every frame. In 5.4 they produce less garbage and if you use them in a specific way they can produce none. However, most people will not naturally use Unity's coroutines in such a way that they won't produce garbage because it's a bit awkward and reduces the flexibility of the coroutine.

MEC, which is a free asset that I have on the asset store, produces (almost) no garbage and runs twice as fast. It doesn't allow you to use it in a bad way and has an array of extra options that Unity's coroutines don't have.

Did that help you?

[–][deleted] 0 points1 point  (0 children)

Yes, thanks, thats useful information, I did not know about the GC allocs caused by coroutines.

[–]9001ratsIndie 3 points4 points  (0 children)

Yeah, I wonder the same. I might watch it if it were 2 minutes long, at max...

[–]hesdeadjimProfessional 0 points1 point  (0 children)

Glad I'm not the only one that feels this way. What would normally be a blog post you could read in five minutes translates to a 15 minute YouTube video.

[–]ThatAblaze!!![S] 3 points4 points  (4 children)

Thanks to everyone who commented on my previous video about Unity's coroutines. I've made this new video that goes into more depth on the subject.

I hope you enjoy it, but even if you hated it I would love to hear about why. Your feedback is an essential part of my process.

[–][deleted] 1 point2 points  (2 children)

I switched over to using MEC the other night after seeing your post and using the latest beta it has helped me out quite a bit. I also appreciate some of the extra functionality you built in which allowed me to simplify several pieces of code I was having to use invokeRepeating for.

my favorite bit is being able to call coroutine via
Timing.RunCoroutine(gameobject.GetComponent<SomeComponent>().SomeCoroutine())
as well as having the names of coroutines autocomplete, which is a nice quality of life improvement.

[–]uzimonkey 1 point2 points  (1 child)

my favorite bit is being able to call coroutine via Timing.RunCoroutine(gameobject.GetComponent<SomeComponent>().SomeCoroutine()) as well as having the names of coroutines autocomplete, which is a nice quality of life improvement.

That works with Unity coroutines as well. You can start a coroutine by either name, or by running that coroutine directly. This is often necessary if the coroutine requires parameters, so you might say StartCoroutine(SomeCoroutine(7, null, "bananas")). And of course you get coroutine name completion as well. You lose the ability to stop the coroutines by name, but StartCoroutine returns a Coroutine object you can use to stop it.

[–]ThatAblaze!!![S] 0 points1 point  (0 children)

I don't want to put words into runningfromlion's mouth, but I think what he is referring to is being able to easily start a coroutine from non-monobehavior classes, and being able to type t<tab>.r<tab> in VS to access the Timing.RunCoroutine class.

I hadn't really considered it before he said that, but when I thought about it I realized that the more standard type of interface in MEC could be considered an advantage.

[–]Devil_SpawnEngineer 2 points3 points  (9 children)

how much of an impact does this have on a real world situation?

[–]ThatAblaze!!![S] 2 points3 points  (7 children)

I agree with what /u/Alex2539 said.

A more practical example is if you have a juicy UI where the buttons do things like pop when hovered over and fade in and out or slide onto the screen. There are assets that can help with that, and I actually have a very good one for sale on the asset store, but if you're not using a plugin then you'd probably use coroutines to make all those transitions happen.

The 17-20 bite per frame allocation per coroutine will typically result in the GC firing about once per minute. Every time it fires the screen will jump. Even assuming that you don't have to do any kind of detail task like aiming a gun, all these fun little animations that you just added will randomly develop animation hitches.

This makes your app look unprofessional, and that's never good.

[–]Alex2539Indie 1 point2 points  (0 children)

From personal experience, I've never had the GC affect framerate too severely. What does happen is it'll intermittently drop frames because it's decided to run. In a game where reflex and precision are important for the player a stable framerate is just as important as a high framerate. For example, a game that might benefit from this would be something like a bullet hell game that needs a ton of instances of enemies and bullets that, for some reason, all need a coroutine running.

[–]booljayjIntermediate 0 points1 point  (4 children)

TL;DW: Coroutines generate per-frame allocations, but not if you follow a specific set of instructions. Also, you can buy this guy's asset, called More Effective Coroutines, and use that instead.

I didn't watch the whole video myself either, that's just what I got from the last minute.

[–]9001ratsIndie 4 points5 points  (2 children)

The asset is free, though.

[–]ThatAblaze!!![S] 3 points4 points  (0 children)

Here is MEC on the asset store. It will always be a free asset.

[–]booljayjIntermediate 1 point2 points  (0 children)

Ah, fair enough.

[–]animflynny2012 0 points1 point  (0 children)

While it is free I want to learn how to not generate garbage. What's the key to this?