- Home /
public not showing up
Anybody has an idea why my public not showing up inspector.My script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class WeaponManager : MonoBehaviour {
public List<Gun> Weapons = new List<Gun>();
public List<string> WeaponNames = new List<string>();
public int CurWeapon;
public static WeaponManager Instance;
// Use this for initialization
void Start () {
Instance = this;
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
CurWeapon = GUILayout.SelectionGrid (CurWeapon, WeaponNames.ToArray(), 4);
}
public static void FindWeapon(string Name)
{
foreach (Gun Gu in Instance.Weapons)
{
if(Name == Gu.Name)
return Gu;
}
return null;
}
}
Another public that i put in my other script is also not showing up.
Which public is not showing up? Is it all of them, or just some. I know there are certain types that Unity doesn't support assigning in the inspector.
Its also possible that your script hasn't refreshed since your last update.
^^ Also that static Weapon$$anonymous$$anager won't show in the inspector because all prefabs are essentially instances, so it wouldn't make sense to be able to assign statics in any spcific prefab.
Only curWeapon is meant to show up. Statics don't, neither do lists in normal mode.
What do you mean that lists don't? Lists of serializable types do show up.
Answer by AlkisFortuneFish · Jul 05, 2014 at 11:34 AM
The inspector only shows instance fields that it can serialize.
Pasting from the recent Unity Serialization blog post:
What does a field of my script need to be in order to be serialized?
Be public, or have [SerializeField] attribute
Not be static
Not be const
Not be readonly
The fieldtype needs to be of a type that we can serialize.
Which fieldtypes can we serialize?
Custom non abstract classes with [Serializable] attribute.
Custom structs with [Serializable] attribute. (new in Unity4.5)
References to objects that derive from UntiyEngine.Object
Primitive data types (int,float,double,bool,string,etc)
Array of a fieldtype we can serialize
List of a fieldtype we can serialize
In your case, the serializable fields are the WeaponNames list and CurWeapon. I presume that you want your Weapons list to be shown as well but to do that you need to show us your Gun class. I suspect that it is not a serializable class or a class deriving from UnityEngine.Object through ScriptableObject or MonoBehaviour.
If it is a serializable data class, the serialization system will serialize the contents of your objects into WeaponManager and display the members of each instance in your list.
If it is a ScriptableObject class, a MonoBehaviour class or anything else deriving from Object, you will see a list of Object references instead.
If this answer helped you, please click accept. Otherwise, please let us know that it didn't. It's rude to ask for people's help, have them spend their time to try and help you and then disappear.