GrabPass + Dynamic Batching == Friendship 🤜🤛

Important note: it appeared that this trick is not working in Unity 2017.2 and higher. Since currently my primary version is 2017.1.3 I have no time to experiment and find solution for the mentioned versions 😕


GrabPass is probably the easiest way to get the content of the screen and pass it to the shader automagically. Later you can use this texture to make some nifty effects like distortion and reflection.

But GrabPass has a huge fault: it breaks the dynamic batching 💔

Read more

Share Comments

Why I don't like Dictionary.TryGetValue and how I made it better (I hope)

The most annoying thing of Dictionary.TryGetValue is that it returns a default value of value parameter if key is not found. E.g. if value is of float type it will be 0.0f.
Because of that you have to check the returned bool and if it’s false you have to assign the value you need. It looks as follows

As you can see now we have to deal with redundant if statement which makes code not so clean and neat as it could be.
How about this one?

Fortunately it’s quite easy to make it real with an extension class like as follows


Share Comments

StableEnum or: How I Learned to Stop Worrying and Love the Enums in Unity3d

It’s a well-known problem with serialization of enums in Unity3d:

  1. Use enum as a serialized field in your MonoBehaviour or ScriptableObject (or anything serializable).
  2. Fine-tune everything and code your game further casually.
  3. Add some new enumerators in the middle of your enum.
  4. BAM!! You are screwed.

What happened? Nothing fancy: new enumerators of your enum just shifted down the old ones occupying their values, because Unity serializes enums as ints.
Solution is easy: serialize enums as strings. And StableEnum will help you with this.

Share Comments

Nested canvas bug

Weird bug related to UI.Canvas was accidentally found by me while I was developing new menu for our upcoming game SummerCatchers. Btw, follow us ;)
As far as you may know Canvas can have other Canvases as children objects. This is very useful in optimization purpose because sub-canvas isolates its UI elements from other canvases (parent and siblings) thus modifying one of its children won’t cause rebuilding of batched mesh for other canvases.
The bug is as follows.

Read more

Share Comments

Enum flags in Unity3d Inspector

It’s quite strange but Unity can’t show your enum as bitmask / flags out of the box.
Fortunately this can be fixed fast and easy.

Read more

Share Comments

git init

This is it. I joined the dark side and now I have a blog.

Share Comments