Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by adjnor · Oct 18, 2015 at 09:10 AM · animationeditoranimatorbehaviourstate machine

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? alt textalt text Thanks

untitled2.png (45.9 kB)
untitled.png (7.6 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image adjnor · Oct 18, 2015 at 03:51 PM 0
Share

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

avatar image meat5000 ♦ adjnor · Oct 18, 2015 at 07:21 PM 0
Share

No problem. Glad to help!

avatar image
1

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:

attackbehaviour

edit

Also make sure you named the file that contains this behaviour "AttackBehaviour.cs".


attackbehaviour.png (59.0 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image adjnor · Oct 18, 2015 at 08:12 PM 0
Share

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!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Animation does not start 1 Answer

Easier way of creating transitions in the animator? 1 Answer

Animation playing in editor but not on android 0 Answers

How to tell if an animation clip is playing in the editor(NOT in playmode) with an editor script 1 Answer

The animated object returns to its initial state 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges