Some public attributes not shown in inspector, default references

In my script, I have several public attributes. Some of them are visible in the inspector, others are not. Why?

using UnityEngine;
using System.Collections;

public class TestInspector : MonoBehaviour {
	public string str; // not visible
	public int i;      // not visible
	public float f;    // not visible
	public GameObject go;      // visible
	public AnimationClip anim; // visible

I select the TestInspector script in the project. The script itself, not a GmeObject with the script attached in the Hierarchy! So I’m talking about the Default References.

When I select an object, that has the script attached, all attributes are visible in the inspector. But I want to set all the default values for the script in the inspector, not in code.

public is shown in the editor but only public instance values. Static will never show in the editor as it is not related to the instance of the monobehaviour, its a class value thats unique application wide.

If you want to expose this kind of information you must write a CustomEditor for your class

Why do you use an abstract class? Usually it’s better to keep the inheritance chain short. If you really need some kind of base class, use only one. For other dependencies it’s better to use interfaces and define methods and properties.

Anyway, i’ve tested your setup and the inspector show all variables as it should:


Properties aren’t serialized and therefore never show up in the inspector. The property “InteractionName” is actually a bit useless since you just wrap another public variable.

If you want to display properties, you need to implement a custom inspector for your class.

For what you want to do the whole thing would look like the one below assuming you want to set chopdown basing on the class, not through editor (but in case of editor you wouldn't set it anywhere in code but do it on the prefab)

public class Lumber : GameObjectInteraction {

  public GameObject trunkPrefab;
  void Awake ()
    interactionName = "Chop down";

public abstract class GameObjectInteraction : Interaction {}

public abstract class Interaction : MonoBehaviour {

  public static readonly Vector2 NULL_VECTOR2 = new Vector2(float.NaN, float.NaN);
  public static readonly Vector3 NULL_VECTOR3 = new Vector3(float.NaN,float.NaN,float.NaN);

  protected string interactionName;
  private float maxDistanceSquare = 2.5f;
  private int importance = 1;