Conversation

unity programming update: "i want a generic way to play back a sequence of actions" --- me, ten seconds before reinventing coroutines from first principles

1
0
1

this post inspired by looking at the interface i just wrote and realizing it's pretty much just IEnumerable but without the compiler magic

1
0
1

dunno how off base i am but unity's implementation of coroutines really seems like a shiny rake labelled "step on me" huh

2
0
1

@eclairwolf yeah they’re uh,, bad. for a lot of reasons, actually

there’s a few third party options out there that are pretty good

  • more efficient coroutines is older but still gets the job done if you want a pretty drop-in replacement
  • unitask
  • the observable big sibling to unitask, r3. i really like this one
2
0
1

@rowan ooh! been meaning to spend some time looking into r3!

0
0
1

eli (ˈe̝ːli), vampire kitsune

@eclairwolf like the three major problems i have with the standard coroutines is that you can’t return values from them, they’re not very well synced to the game loop, and they generate a ton of garbage and GC pressure if you’re not careful.

0
0
1

@eclairwolf Aren't coroutines a C# thing rather than a Unity thing? I haven't looked at this in a long time

1
0
0

@socks they're kinda halfway in between a language feature and a library thing - c# does some fancy compiler things to turn IEnumerable generator functions (yield return) into state machines under the hood, which is 99% of the way to being a coroutine, and unity has an api for scheduling them

since it's an old unity feature it's 99% footgun by volume tho

0
0
0