Only certain types appear in script inspector?

I’ve noticed In script inspector, only certain types appear. Types such as float and int do not appear, whereas types such as GameObject appear.

However, if a game object is linked with the script, then all public fields do appear in the game object inspector. Why is this?

You probably talk about the “default references” which you can set on the script asset itself. The default references are a pure editor feature and have no influence on the runtime. As the name suggests you can only set asset references (references to classes derived from UnityEngine,Object such as GameObject, Transform, MonoBehaviour, Mesh, …).

Those default references can’t take references to scene objects since they are stored with the script asset itself. That’s the same limitation as for prefabs. Default references are a way to automatically link certain assets to script instances when they are added to a GameObject in the editor.

If you want to setup default values for other variables, create a prefab and instantiate it. You can’t specify default values for scripts. They take their default values from the class itself whatever you’ve specified in the code.

public float test = 5f;

A new script instance with that variable will have the defauit value of “5” when added to a gameobjet for the first time.

Since you can’t specify refereces to other assets as constants inside the code Unity added the default references section to the script inspector.

Again, this is a pure editor feature. If you add a script with AddComponent at runtime those references won’t be set, only when added inside the editor via UI actions.