Don't wanna be here? Send us removal request.
Text
Start, Awake, Update and StartCoroutine in Unity.
In Unity, Coroutines leverage C#'s IEnumerator/yield syntax feature to easily let you write stepwise behaviors that execute over a longer amount of time/over multiple update cycles within just one method.
But when exactly do they get executed?
Of course, some of it is documented in their classic manual page: Order of Execution (2021.3)
But there's a strange thing I didn't really think of when I started using Coroutines so I thought I'd document it here.
When does the first step of a coroutine execute? And if I started a coroutine in Awake, and another in Start, would the code after yield null execute sequentially after the next Update?
The answer may not be what you expect.
Here's some code to test:
Stick it on a GameObject, run the scene and let's see what we got.
huh...
A few notable observations:
Stuff before the first yield null execute immediately as if they were where the StartCoroutine call is.
Using StartCoroutine in Start seems to make the first yield null skip one Update. This kind of makes practical sense, since the common intention of a yield return null is you want it to wait for one update. If it happened in the first update after Start, it would be as if it didn't wait at all.
So really, the thing to remember is: Stuff after the first yield null in Awake executes right after the first update. Stuff after the first yield null in Start executes right after the second update.
1 note
·
View note
Photo
It's 2022 and no such "new MonoBehaviour" has emerged. But people are still making damn good games in Unity.
Like many pieces of closed-source software, the inner workings of Unity Engine can be a mystery sometimes. Luckily, some answers can be fished out by some well placed Debug.Log calls.
A few months ago, I wanted to find out the order in which methods get called when you call AddComponent. Sometimes you need to instantiate components that instantiate their components and you don’t have a chance to initialize its fields.
More to the point: It turns out that by the time AddComponent returns, that new Component’s Awake will have been already called. Check out the screenshots above.
Unity Boston (2015) featured a talk on Unity’s feature/development roadmap. And more than what’s outlined on their page for it, it sounds like they have plans for a new scripting component base class (essentially “a new MonoBehaviour” which fixes and improves upon what they learned from their “design mistakes from 10 years ago” when they first made the architectural decisions behind MonoBehaviour, like magic methods and lifetime callback order.) I don’t expect to see this for another couple of years but it’s nice to see a bright API future ahead of us.
2 notes
·
View notes
Link
If you've read the Unity blog post about their custom == operator overload, this post is a good, deeper investigation into alternatives, performance and possibly unexpected results.
2 notes
·
View notes
Photo
git pull と git pull –rebase の違いって?図を交えて説明します! | KRAY Inc http://kray.jp/blog/git-pull-rebase/
28 notes
·
View notes
Text
public class ButtBehavior : MonoBehaviour { void Start () { Debug.Log("Yay for syntax highlighting on this tumblr!"); } }
For this, we must celebrate. Aww. it only works on the site, not the dash.
0 notes
Link
I recently ran into this peculiar behavior. System.Action myAction = condition ? DoSomething : DoAnother; That doesn't work. But see what does, and an explanation, in the link.
0 notes
Photo

How do you convert a quadratic bezier to a cubic bezier?
http://stackoverflow.com/questions/3162645/convert-a-quadratic-bezier-to-a-cubic
Yes, I doodled a face under my bezier curve. What of it?
0 notes
Link
1 note
·
View note
Link
This formed the basis of my understanding of the game loop timestep back in the day. Made it really easy for me to glean what Unity and other engines do for you under the hood, and why it works how to get some things to work.
1 note
·
View note
Link
This is a good rundown of some methods (and mistakes) that people may make when implementing jumping. But I can't say I agree completely with the conclusion.
The decreasing force solution isn't that clean and it seems considerably more difficult to calculate/plan for in terms of level design. But for the genre it was used in, that probably doesn't matter.
More important is whatever feel was judged to be a good fit. I've certainly gone through the jetpack phase in my earlier days of programming platformer physics from scratch. I didn't even know about fixed timestep back then.
But for a more discretely designed platformer with exploration-heavy levels, I find that the simpler jump solution that's nicely controllable is a variant of "The Velocity Cut".
Basically: Instead of making the velocity.y 0, you can halve it or reduce it by some factor so the jump stops but still has palpable inertia to it. It actually feels like Mario or Megaman to me. I wouldn't be surpised this actually was their solution for the classics.
0 notes
Photo
Like many pieces of closed-source software, the inner workings of Unity Engine can be a mystery sometimes. Luckily, some answers can be fished out by some well placed Debug.Log calls.
A few months ago, I wanted to find out the order in which methods get called when you call AddComponent. Sometimes you need to instantiate components that instantiate their components and you don’t have a chance to initialize its fields.
More to the point: It turns out that by the time AddComponent returns, that new Component's Awake will have been already called. Check out the screenshots above.
Unity Boston (2015) featured a talk on Unity's feature/development roadmap. And more than what's outlined on their page for it, it sounds like they have plans for a new scripting component base class (essentially "a new MonoBehaviour" which fixes and improves upon what they learned from their "design mistakes from 10 years ago" when they first made the architectural decisions behind MonoBehaviour, like magic methods and lifetime callback order.) I don't expect to see this for another couple of years but it's nice to see a bright API future ahead of us.
2 notes
·
View notes
Link
To change this template, close your Unity editor, go to Unity installation directory, then into Editor/Data/Resources. For example:
Windows C:\Program Files (x86)\Unity\Editor\Data\Resources
Mac /Applications/Unity/Editor/Data/Resources
This is great for when you want to add usings at the top for all your new scripts, and also if you want to remove the template Start and Update methods.
0 notes
Link
Explains what each HideFlags value does.
0 notes
Link
1 note
·
View note
Link
0 notes