Let's talk about @unity3d, and the execution order of its event functionsโ€”such as ๐š‚๐š๐šŠ๐š›๐š and ๐š„๐š™๐š๐šŠ๐š๐šŽ.

Trust me when I say that ...IT'S WAY MORE COMPLICATED THAN YOU THINK. ๐Ÿ˜ฌ

#gamedev #unitytips #madewithunity

๐Ÿงต๐Ÿ‘‡
๐Ÿ”น๐—™๐—ถ๐—ฟ๐˜€๐˜ ๐—ฆ๐—ฐ๐—ฒ๐—ป๐—ฒ ๐—น๐—ผ๐—ฎ๐—ฑ

1โƒฃ ๐™ฐ๐š ๐šŠ๐š”๐šŽ: always called before any ๐š‚๐š๐šŠ๐š›๐š & after a prefab is instantiated

2โƒฃ ๐™พ๐š—๐™ด๐š—๐šŠ๐š‹๐š•๐šŽ: called just after a ๐™ถ๐šŠ๐š–๐šŽ๐™พ๐š‹๐š“๐šŽ๐šŒ๐š is enabled (including when loaded, created, or a ๐™ผ๐š˜๐š—๐š˜๐™ฑ๐šŽ๐š‘๐šŠ๐šŸ๐š’๐š˜๐šž๐š› script is added)
๐Ÿ”น๐—•๐—ฒ๐—ณ๐—ผ๐—ฟ๐—ฒ ๐˜๐—ต๐—ฒ ๐—ณ๐—ถ๐—ฟ๐˜€๐˜ ๐—ณ๐—ฟ๐—ฎ๐—บ๐—ฒ ๐˜‚๐—ฝ๐—ฑ๐—ฎ๐˜๐—ฒ

3โƒฃ ๐š‚๐š๐šŠ๐š›๐š: called before the first frame update. This happens only if the script is enabled. ๐š‚๐š๐šŠ๐š›๐š can also be made into a coroutine by changing its return type to ๐™ธ๐™ด๐š—๐šž๐š–๐šŽ๐š›๐šŠ๐š๐š˜๐š›
๐Ÿ”น๐—ฃ๐—ต๐˜†๐˜€๐—ถ๐—ฐ๐˜€ ๐—จ๐—ฝ๐—ฑ๐—ฎ๐˜๐—ฒ

4โƒฃ ๐™ต๐š’๐šก๐šŽ๐š๐š„๐š™๐š๐šŠ๐š๐šŽ: often called several times during each frame. This is where the rigid bodies are updated.

This is also where you should call methods that *continuously* affect the physics, such as ๐™ฐ๐š๐š๐™ต๐š˜๐š›๐šŒ๐šŽ (when non-impulsive).
The physics event functions are invoked after each ๐™ต๐š’๐šก๐šŽ๐š๐š„๐š™๐š๐šŠ๐š๐šŽ call:

5โƒฃ ๐™พ๐š—๐šƒ๐š›๐š’๐š๐š๐šŽ๐š›๐š‡๐š‡๐š‡
6โƒฃ ๐™พ๐š—๐™ฒ๐š˜๐š•๐š•๐š’๐šœ๐š’๐š˜๐š—๐š‡๐š‡๐š‡

They might be out-of-synch with the game logic. To fix this, you can use ๐šข๐š’๐šŽ๐š•๐š ๐š†๐šŠ๐š’๐š๐™ต๐š˜๐š›๐™ต๐š’๐šก๐šŽ๐š๐š„๐š™๐š๐šŠ๐š๐šŽ in a coroutine.
๐Ÿ”น๐—จ๐—ฝ๐—ฑ๐—ฎ๐˜๐—ฒ ๐—ข๐—ฟ๐—ฑ๐—ฒ๐—ฟ

7โƒฃ ๐š„๐š™๐š๐šŠ๐š๐šŽ: called once per frame on any active game object. This is where you want to put most of your game logic.

This is also where you should call one-time event input functions such as:

๐Ÿ”ธGetKeyDown
๐Ÿ”ธGetKeyUp

๐Ÿ”ธGetButtonDown
๐Ÿ”ธGetButtonUp
That is very confusing! ๐Ÿ˜–

So this is a quick & overly simplified table to show you which methods should be safe to call from which event functions.

TL;DR:

๐Ÿ”ธOne-time input events & game logic? โž” ๐š„๐š™๐š๐šŠ๐š๐šŽ
๐Ÿ”ธAffecting physics over multiple frames? โž” ๐™ต๐š’๐šก๐šŽ๐š๐š„๐š™๐š๐šŠ๐š๐šŽ
8โƒฃ ๐™ป๐šŠ๐š๐šŽ๐š„๐š™๐š๐šŠ๐š๐šŽ: called after *all* ๐š„๐š™๐š๐šŠ๐š๐šŽ functions have been called.

It is pretty handy because you can assume that all game objects have been correctly updated.
๐Ÿ”น๐—ฆ๐—ฐ๐—ฒ๐—ป๐—ฒ ๐—ฅ๐—ฒ๐—ป๐—ฑ๐—ฒ๐—ฟ๐—ถ๐—ป๐—ด

9โƒฃ ๐™พ๐š—๐š๐šŽ๐š—๐š๐šŽ๐š›๐™ธ๐š–๐šŠ๐š๐šŽ: called after the scene rendering is complete. This is used to allow for post-processing.

A few years ago I wrote a tutorial about screen shaders, and how to use them for post-processing.
alanzucconi.com/2015/07/08/scrโ€ฆ
There are many more event functions that are called before ๐™พ๐š—๐š๐šŽ๐š—๐š๐šŽ๐š›๐™ธ๐š–๐šŠ๐š๐šŽ, but those are rarely used.

In case you are interested, they are:

๐Ÿ”ธOnWillRenderObject
๐Ÿ”ธOnPreCull
๐Ÿ”ธOnBecameVisible
๐Ÿ”ธOnBecameInvisibile
๐Ÿ”ธOnPreRender
๐Ÿ”ธOnRenderObject
๐Ÿ”ธOnPostRender
๐Ÿ”น ๐——๐—ฒ๐—ฐ๐—ผ๐—บ๐—บ๐—ถ๐˜€๐˜€๐—ถ๐—ผ๐—ป๐—ถ๐—ป๐—ด

๐Ÿ”Ÿ ๐™พ๐š—๐™ณ๐š’๐šœ๐šŠ๐š‹๐š•๐šŽ: this method mirrors the behaviour of ๐™พ๐š—๐™ด๐š—๐šŠ๐š‹๐š•๐šŽ, being called when the ๐™ผ๐š˜๐š—๐š˜๐™ฑ๐šŽ๐š‘๐šŠ๐šŸ๐š’๐š˜๐šž๐š› becomes disabled or inactive.
There are many more methods I could simply not fit in this thread. ๐Ÿคฏ

Most of the info comes from the official Unity documentation. You should definitely have a look at it if you are interested! ๐Ÿ“–๐Ÿ‘‡

docs.unity3d.com/Manual/Executiโ€ฆ
โœจ ๐’•๐’‰๐’‚๐’๐’Œ ๐’š๐’๐’– ๐’‡๐’๐’“ ๐’„๐’๐’Ž๐’Š๐’๐’ˆ ๐’•๐’ ๐’Ž๐’š ๐’•๐’†๐’… ๐’•๐’‚๐’๐’Œ โœจ

I write about #gamedev, shader coding, programming & artificial intelligence.

๐ŸŽฎ๐ŸŒˆ๐Ÿ–ฅ๏ธ๐Ÿค–

If you are interested in any of those topics, follow me for more content like this! โ˜บ๏ธ

patreon.com/AlanZucconi

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Alan Zucconi

Alan Zucconi Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @AlanZucconi

22 Feb
Let's talk about NEURAL NETWORKS. ๐Ÿง 

Most of you are probably familiar with them. ๐Ÿง‘โ€๐Ÿ’ป

But not many know HOW they actually work andโ€”even more importantlyโ€”WHY they work. ๐Ÿ”ง

So, let's take a journey to understand what makes Neural Networks so effective... ๐Ÿ“Š

#ML #AI #NN

๐Ÿงต๐Ÿ‘‡
Let's start with a simple question...

โ“ What problem are NNs trying to solve? ๐Ÿค”

Generally speaking, NNs are trained on examples, to produce predictions based on some input values.

The example data (input + desired output) draws a curve that the NN is trying to fit.
In a nutshell, NNs areโ€”like most ML toolsโ€”a fancy way to fit the curves inherently generated by the examples used to train it.

The more inputs it needs, and the more outputs it produces, the higher the dimension of the curve.

The simplest curve we can fit is ...a line! ๐Ÿ˜…
Read 21 tweets
10 Feb
This is a list of TEN (plus one) games that are "accidentally" TURING COMPLETE. ๐Ÿ–ฅ๏ธ

In a nutshell, when a game is Turing Complete you can use it to build a WORKING COMPUTER. ๐Ÿคฏ

If you are a parent: please don't underestimate games as a creative medium.

Let's start with...

๐Ÿงต๐Ÿ‘‡ ImageImageImage
1โƒฃ Minecraft โ›๏ธ

Unsurprisingly, @Minecraft is indeed Turing Complete. ๐Ÿ–ฅ๏ธ

This is possible thanks to the so-called REDSTONE CIRCUITS, which allow to build simple logic gates. ๐ŸŸฅ

And if you are really, REALLY committed ...you can even build a computer!

2โƒฃ Portal 2 ๐ŸŸ ๐Ÿ”ต

Yes. Everybody's favourite game is Turing Complete! ๐Ÿฅฐ

@anklejbiter used Portal 2 level editor to create a 3-Digit Binary Calculator. De-facto proving it can be used for arbitrary computation.

steamcommunity.com/sharedfiles/fiโ€ฆ
Read 14 tweets
2 Feb
After using @unity3d for almost 10 years, I want to share the TEN small features that are really helping me develop games faster.

Starting with my favourite... ๐Ÿ˜Ž

1โƒฃ Inspector Maths

You can write ACTUAL mathematical expressions in the inspector! ๐Ÿคฏ

Check the other ones!

๐Ÿงต๐Ÿ‘‡
2โƒฃ Animation Curves

Unity supports a super easy way to create smooth paths through ANIMATION CURVES. Perfect for blending & animating properties.

Creation:
public AnimationCurve Curve;

Usage:
float x = Curve.Evaluate(t);

#unitytips

docs.unity3d.com/ScriptReferencโ€ฆ
3โƒฃ Gradients

The equivalent of AnimationCurve for colours is Gradient. You can use it to create and sample smooth gradients.

Creation:
public Gradient Gradient;

Usage:
Color c = Gradient.Evaluate(t);

#unitytips

docs.unity3d.com/ScriptReferencโ€ฆ
Read 10 tweets
25 Jan
These are FIVE TRICKS that my colleagues and I have learnt from one academic year or REMOTE TEACHING in HIGHER EDUCATION. ๐Ÿ“š๐ŸŽ“

Every class is different, and every lecture has their own teaching style. But feel free to share this thread if you think it might help someone!

๐Ÿงต๐Ÿ‘‡
1โƒฃ ๐—ฆ๐—ฒ๐˜๐˜‚๐—ฝ ๐Ÿ–ฅ๏ธ

If you are using PowerPoint with a second monitor, you can actually resize the "Presenter View" window:

1โƒฃ๐Ÿ–ฅ๏ธ
๐Ÿ”ดShared screen with slides

2โƒฃ๐Ÿ–ฅ๏ธ
๐Ÿ”ตPresenter view with notes
๐ŸŸขMS Teams chat

So you can share your screen, see your notes & read questions!
2โƒฃ ๐—–๐—น๐—ฎ๐—ฝ๐—ฝ๐—ถ๐—ป๐—ด ๐—ผ๐—ป ๐— ๐—ฆ ๐—ง๐—ฒ๐—ฎ๐—บ๐˜€ ๐Ÿ‘

Every time a student present their work in front of the class, I invite everyone to clap. ๐Ÿ‘

A remote alternative is to encourage students to raise and lower their hands on MS Teams quickly.
Read 7 tweets
23 Jan
BEHAVIOUR TREES are the cornerstone of ARTIFICIAL INTELLIGENCE for #gamedev.

But they can be difficult to "grow". ๐ŸŒฑ

I have selected FIVE rather approachable papers that use EVOLUTION to grow behaviour trees AUTOMATICALLY, so you don't have to. ๐ŸŒฒ

Let's start with...๐Ÿ“

๐Ÿงต๐Ÿ‘‡ ImageImage
1โƒฃ "Evolving Behaviour Trees for the Commercial Game DEFCON" (2010)

๐Ÿ”นChong-U Lim
๐Ÿ”นRobin Baumgarten
๐Ÿ”นSimon Colton

researchgate.net/publication/22โ€ฆ ImageImage
2โƒฃ "Learning of Behavior Trees for Autonomous Agents" (2015)

๐Ÿ”นMichele Colledanchise
๐Ÿ”นRamviyas Parasuraman
๐Ÿ”นPetter ร–gren

arxiv.org/abs/1504.05811 ImageImage
Read 8 tweets
22 Jan
Fifty years have passed since CONWAY'S GAME OF LIFE firstly appeared on a column called "Mathematical Games" on @sciam.

While most Programmers & Computer Science enthusiasts are familiar with it, not many know that the game is actually TURING COMPLETE.

Let's see why. โ  โ ต

๐Ÿงต๐Ÿ‘‡
The quickest way to prove that a system is TURING COMPLETE is to show that it allows for the constructions of LOGIC GATES. ๐Ÿ–ฅ๏ธ

So, let's see how the ๐—”๐—ก๐——, ๐—ข๐—ฅ and ๐—ก๐—ข๐—ง gates can actually be constructed in Conway's Game of Life...
Firstly, we need to find a way to encode binary signals.

One very popular choice is to use a stream of GLIDERS. The so-called GOSPER GLIDER GUN can generated a new glider every 30 generations. ๐Ÿ”ซ

Hence, receiving a glider every 30 generations counts as a "1".
Read 11 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!