- Home /
State Machine Behaviour public variable not assignable from editor?
Hello,
I have been trying to write a state machine behaviour, and after reading the docs it seems pretty clear that public variables should be assignable from the editor. Take a look at this from the docs:
public class AttackBehaviour : StateMachineBehaviour
{
public GameObject particle;
public float radius;
public float power;
protected GameObject clone;
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
clone = Instantiate(particle, animator.rootPosition, Quaternion.identity) as GameObject;
var rb = clone.GetComponent<Rigidbody>();
rb.AddExplosionForce(power, animator.rootPosition, radius, 3.0f);
}
As you can see, there are 3 public variables and none of them are defined. Moreoever, the particle object clearly seems to be a prefab that is instantiated, while the radius and power are floats that I suppose are assigned from the editor too. What I do not understand is why in my editor there is absolutely no way to assign these variables? I have literally copy pasted the code from the docs and nothing shows up, am I missing something? Thanks
Answer by meat5000 · Oct 18, 2015 at 02:59 PM
Make sure you have fixed all errors in the console. This will prevent your script compiling properly and variables wont show in editor. If there are no errors make sure you have saved scene and project.
I had no errors in the console, but after saving everything and closing my visual studio editor the variables showed up. Not sure what happened but it works! Well thanks :) Can you edit your comment as an answer so that I can select it? Thanks
Answer by Bunny83 · Oct 18, 2015 at 07:18 PM
Are you sure you did not create a custom inspector for your class? If i copy&paste the example from the docs, create a new state and add the beahviour i get this:
edit
Also make sure you named the file that contains this behaviour "AttackBehaviour.cs".
I am sure it was the default unity inspector and my file name was indeed AttackBehaviour.cs, same as class name. It worked after saving and closing my scripting editor, a bit strange but it's good now!