воскресенье, 9 апреля 2017 г.

Top100 Unity errors

In my programming practice, I encountered many code construction errors. Most worse are hidden. All works, but bugfixing and extending functionality is a nightmare. I will write some which are funny or puzzling in my blog.

1. Created object shows "null" in debugger.

Suppose code:
public class LocationsDB : MonoBehaviour { ... }

locationsDB = new LocationsDB();
Why do you think, debugger can say us, that locationsDB is "null" ?


Answer
Easily, ToString() implementation returns "null" (see UnityEngine.Object.ToString()). Why is that? You see, in Unity, MonoBehaviours are used as components of GameObject, additionally they are created in a special way, for example:
gameObject.AddComponent<A>();

Комментариев нет:

Отправить комментарий