Tag Archives: Tip

Controlling ScriptableObject instantiation

ScriptableObjects become (unfortunately) necessary when you start developing editor tools. That, and every other class that inherits from UnityEngine.Object, has the unique ability to maintain proper references after deserialization. Every other class creates a copy per reference (as if it were a struct) after deserialization, which can be very troublesome.

One of the least pleasant aspects of ScriptableObject is that you cannot control their instantiation. Using their constructor to create them does not work as expected. The only proper way to create a ScriptableObject from scratch is to call the ScriptableObject.CreateInstance<DerivedType>() static method, where DerivedType is a type which derives from ScriptableObject. Unfortunately, This method does not take any parameters. I will show you an easy way to help control their instantiation, so that the users of your ScriptableObject classes will be less prone to use them incorrectly.

Continue reading

A better method to recalculate normals in Unity

A visible seam showing after recalculating normals in runtime.

You might have noticed that, for some meshes, calling Unity’s built-in function to   RecalculateNormals(), things look different (i.e. worse) than when calculating them from the import settings. A similar problem appears when recalculating normals after combining meshes, with obvious seams between them. For this post I’m going to show you how RecalculateNormals()  in Unity works and how and why it is very different from Normal calculation on importing a model. Moreover, I will offer you a fast solution that fixes this problem.

This article is also very useful to those who want to generate 3D meshes dynamically during gameplay and not just those who encountered this problem.

Continue reading