How to make Subclass Public Variables appear in inspector menu

I’m trying to get variables of a sub class to appear in the inspector using C#.

using UnityEngine;
using System.Collections;

// Require a character controller to be attached to the same game object
[RequireComponent (typeof(CharacterController))]
[AddComponentMenu("Motor/bit Movement FPS")]
public class bitMovementFPS : MonoBehaviour {
	
	// Does this script currently respond to input?
	public bool canControl = true;
	
	public bool useFixedUpdate = true;
	
	// For the next variables, [System.NonSerialized] tells Unity to not serialize the variable or show it in the inspector view.
	// Very handy for organization!
	
	// The current global direction we want the character to move in.
	[System.NonSerialized]
	public Vector3 inputMoveDirection = Vector3.zero;
	
	// Is the jump button held down? We use this interface instead of checking
	// for the jump button directly so this script can also be used by AIs.
	[System.NonSerialized]
	public bool inputJump = false;
	

public class CharacterMotorMovement {
	// The maximum horizontal speed when moving
	public float maxForwardSpeed   = 10.0f;
	public float maxSidewaysSpeed  = 10.0f;
	public float maxBackwardsSpeed = 10.0f;
	
	// Curve for multiplying speed based on slope (negative = downwards)
	public AnimationCurve slopeSpeedMultiplier = new AnimationCurve(new Keyframe(-90, 1), new Keyframe(0, 1), new Keyframe(90, 0));
	
	// How fast does the character change speeds?  Higher is faster.
	public float maxGroundAcceleration = 30.0f;
	public float maxAirAcceleration    = 20.0f;

	// The gravity for the character
	public float gravity        = 25.0f;
	public float maxFallSpeed   = 20.0f;
	
	// For the next variables, [System.NonSerialized] tells Unity to not serialize the variable or show it in the inspector view.
	// Very handy for organization!

	// The last collision flags returned from controller.Move
	[System.NonSerialized]
	public CollisionFlags collisionFlags; 

	// We will keep track of the character's current velocity,
	[System.NonSerialized]
	public Vector3 velocity;
	
	// This keeps track of our current velocity while we're not grounded
	[System.NonSerialized]
	public Vector3 frameVelocity = Vector3.zero;
	
	[System.NonSerialized]
	public Vector3 hitPoint = Vector3.zero;
	
	[System.NonSerialized]
	public Vector3 lastHitPoint = new Vector3(Mathf.Infinity, 0, 0);
}

CharacterMotorMovement movement = new CharacterMotorMovement();
}

None of the variables inside the sublcass “CharacterMotorMovement” appear in the inspector. How do I get them to appear?

Figured out my issue. In order for a subclass to appear in the inspector the class needs to be both declared public and serialized and the instance of the creation of the variable needs to be public as well.

using UnityEngine;
using System.Collections;

// Require a character controller to be attached to the same game object
[RequireComponent (typeof(CharacterController))]
public class bitMovementFPS : MonoBehaviour {
	
	// Does this script currently respond to input?
	public bool canControl = true;
	
	public bool useFixedUpdate = true;
	
	// For the next variables, [System.NonSerialized] tells Unity to not serialize the variable or show it in the inspector view.
	// Very handy for organization!
	
	// The current global direction we want the character to move in.
	[System.NonSerialized]
	public Vector3 inputMoveDirection = Vector3.zero;
	
	// Is the jump button held down? We use this interface instead of checking
	// for the jump button directly so this script can also be used by AIs.
	[System.NonSerialized]
	public bool inputJump = false;
	
[System.Serializable]
public class CharacterMotorMovement {
	// The maximum horizontal speed when moving
	public float maxForwardSpeed   = 10.0f;
	public float maxSidewaysSpeed  = 10.0f;
	public float maxBackwardsSpeed = 10.0f;
	
	// Curve for multiplying speed based on slope (negative = downwards)
	public AnimationCurve slopeSpeedMultiplier = new AnimationCurve(new Keyframe(-90, 1), new Keyframe(0, 1), new Keyframe(90, 0));
	
	// How fast does the character change speeds?  Higher is faster.
	public float maxGroundAcceleration = 30.0f;
	public float maxAirAcceleration    = 20.0f;

	// The gravity for the character
	public float gravity        = 25.0f;
	public float maxFallSpeed   = 20.0f;
	
	// For the next variables, [System.NonSerialized] tells Unity to not serialize the variable or show it in the inspector view.
	// Very handy for organization!

	// The last collision flags returned from controller.Move
	[System.NonSerialized]
	public CollisionFlags collisionFlags; 

	// We will keep track of the character's current velocity,
	[System.NonSerialized]
	public Vector3 velocity;
	
	// This keeps track of our current velocity while we're not grounded
	[System.NonSerialized]
	public Vector3 frameVelocity = Vector3.zero;
	
	[System.NonSerialized]
	public Vector3 hitPoint = Vector3.zero;
	
	[System.NonSerialized]
	public Vector3 lastHitPoint = new Vector3(Mathf.Infinity, 0, 0);
}

public CharacterMotorMovement movement = new CharacterMotorMovement();
1 Like