BCE0005 HandleUtility unknown on build?

I´ve got the line:

var gpos : Vector2 = HandleUtility.WorldToGUIPoint(gameObject.transform.position);

which works fine when I start it in Unity. But comes with this error when I try to build any player (e.g. webplayer or standalone):

Assets/MyScripts/HULL.js(13,8): BCE0005: Unknown identifier: ‘HandleUtility’.

Any idear what I´m doing wrong? Or workaround?

1 Answer

1

HandleUtility is an editor class! You should only use it inside the UnityEditor, and inside of a folder named ‘Editor’ so that the compiler knows not to include it when trying to build a standalone. For the same functionality, you should be using Camera.main.WorldToScreenPoint (with some transformations)- it functions using the main camera instead of the ‘scene camera’- an invisible, intangible camera which the Editor uses to render the Scene View.