Ohio Bronies - Forums

Peanut Bucker is best pony.

You are not logged in.

#1 2014-12-10 04:44:23

iwtcird
Member

Unity General

I'm a Unity and C# wizard. Ask me anything.

Gotchas and tricks that every Unity programmer must know. I'll add to this list over time as I remember more stuff.

  • Avoid allocating memory whenever you can, otherwise you will get regular slowdowns as Unity pauses execution to clean up memory. Make use of object pools.

  • Use for instead of foreach whenever you can because foreach allocates a new iterator every time.

  • Cache your lookups. Don't call GetComponent every Update, call it once at Start and save the result to a member variable. Properties like transform call GetComponent under the hood, so cache them too.

  • Avoid calling GetComponents (plural). It allocates a new array for the results every time.

  • Don't write yield return new WaitForWhatever() every time. Save it to a variable somewhere and reuse it.

  • Reparenting a GameObject maintains its world coordinates, not the ones it has relative to parent.

>you're not allowed to post links

Are you even trying, Horse News?

Last edited by iwtcird (2014-12-10 04:46:00)

Offline

#2 2014-12-10 08:33:29

Star ★
Pony
Starshine Trotter

Re: Unity General

iwtcird wrote:

>you're not allowed to post links

Are you even trying, Horse News?

Usually you get that after three posts (for cutting down on spam) but I bumped you up because you're real. I think.

I want to play around with Unity some time but I hardly have any free time nowadays - otherwise I'd probably spend like a week just dicking about and making stuff. Know any tutorials that don't assume you've never seen code before?

Offline

#3 2014-12-10 16:39:09

TheKiddoMemester
God of Ruse

Re: Unity General

iwtcird wrote:

I'm a Unity and C# wizard. Ask me anything.

Gotchas and tricks that every Unity programmer must know. I'll add to this list over time as I remember more stuff.

  • Avoid allocating memory whenever you can, otherwise you will get regular slowdowns as Unity pauses execution to clean up memory. Make use of object pools.

  • Use for instead of foreach whenever you can because foreach allocates a new iterator every time.

  • Cache your lookups. Don't call GetComponent every Update, call it once at Start and save the result to a member variable. Properties like transform call GetComponent under the hood, so cache them too.

  • Avoid calling GetComponents (plural). It allocates a new array for the results every time.

  • Don't write yield return new WaitForWhatever() every time. Save it to a variable somewhere and reuse it.

  • Reparenting a GameObject maintains its world coordinates, not the ones it has relative to parent.

>you're not allowed to post links

Are you even trying, Horse News?

>Unity

Woah, look at this wizard of all things casual


My name is not important. What is important is what I’m going to do. I just fuckin’ hate this world. And the human worms feasting on its corpus. My whole life is just cold, bitter hatred. And I always wanted to die violently. This is the time of vengeance and no life is worth saving. And I will put in the grave as many as I can. It’s time for me to kill. And it’s time for me to die. My genocide crusade begins here.

Offline

#4 2014-12-10 17:16:55

Star ★
Pony
Starshine Trotter

Re: Unity General

Okay, let's see you write something in assembly, then.

Offline

#5 2014-12-10 21:47:16

TheKiddoMemester
God of Ruse

Re: Unity General

Starshine ★ wrote:

Okay, let's see you write something in assembly, then.

Well, I just did an insane java program, and I'm pretty sure that is harder so ummmmmmmmmmmmmmmmmmmmm you can just like leave, seriously


My name is not important. What is important is what I’m going to do. I just fuckin’ hate this world. And the human worms feasting on its corpus. My whole life is just cold, bitter hatred. And I always wanted to die violently. This is the time of vengeance and no life is worth saving. And I will put in the grave as many as I can. It’s time for me to kill. And it’s time for me to die. My genocide crusade begins here.

Offline

#6 2014-12-11 03:18:08

Star ★
Pony
Starshine Trotter

Re: Unity General

tumblr_ng166xixce1r9l2xbo6_400.jpg

Offline

Quick reply

Write your message and submit

Board footer

Powdered by FluxBB