Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've got a script which creates raycasts. I wanted to use the (presumably less expensive) Plane.Raycast rather than the GameObject.Collider.Raycast (because the gameobject one has a distance parameter so that's one more check)

I can expose the plane gameobject in my scene easily by simply making a public gameobject variable like this:

public GameObject floor;

however when I turn it into this:

public Plane floor;

It doesn't expose in the scene. Why is this?

share|improve this question
    
Same thing happened to me yesterday. The Plane struct isn't the game thing as a GameObject Plane; it's a geometric representation of a plane used for math calculations. Plane docs. –  Wackidev May 19 '12 at 16:25

1 Answer 1

It's because the only things that show up in the inspector are serializable fields or things that you implement in OnInspectorGUI as a custom editor for that class.

For reference: http://unity3d.com/support/documentation/ScriptReference/SerializeField

Serializable types are:

  • All classed inheriting from UnityEngine.Object, for example Gameobject, Commponent, MonoBehaviour, Texture2D, AnimationClip..
  • All basic data types like int, string, float, bool.
  • Some built in types like Vector2, Vector3, Vector4, Quaternion, Matrix4x4, Color, Rect, Layermask...
  • Arrays of a serializable type
  • List of a serializable type (new in Unity2.6)
  • Enums

Headsup note: if you put one element in a list (or array) twice, when the list gets serialized, you'll get two copies of that element, instead of one copy being in the new list twice.

Now Plane is just a struct that has a Vector3 and a float, so you could use those two serializable types to construct a Plane object at runtime if you really need to.

But my guess is that you really want to leave the serialized field as GameObject so you can point to the plane in the scene.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.