• 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
Question by NukeImYourFather · Aug 12, 2012 at 07:07 PM · c#inspectorfunctionclass

Make inspector show changes of class variable value in function?

Hope you understood my title (question). This is a simplified version of the code to make the concept clearer:

 using UnityEngine;
 using System.Collections;
 
 public class customClasses : MonoBehaviour
 {
     public CharacterAttributes playerAttributes = new CharacterAttributes();
 
     public void Start()
     {
         playerAttributes.level = 12; //these two changes does now show
         playerAttributes.name = "Cpt. Awesome"; //but i want these changes to show
     }
 }
 
 [System.Serializable] //makes the class variables show in inspector
 public class CharacterAttributes
 {
     public string name; //shows with value "" (this is correct)
     public int level; //shows with value 0 (so is this)
 }

So... i have successfully made the class variables show in inspector, BUT not the changes i perform in the top function "Start"

Comment

People who like this

0 Show 2
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 Loius · Aug 12, 2012 at 07:35 PM 0
Share

Changes made during the game aren't supposed to affect the Inspector's values. You could save/load on a file if you need to set things through gameplay, or you could expand the Editor itself.

What are you trying to do with this? Maybe we can help more better if we know what you're trying to accomplish. (like "i want to set player spawn point by walking there" or something)

avatar image Bunny83 · Aug 13, 2012 at 01:50 AM 0
Share

@Vicenti: Who said that? Of course changes made at runtime does affect the inspector and the hierarchy since at runtime you run on a copy of your scene.

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Bunny83 · Aug 12, 2012 at 07:24 PM

Remove "= new CharacterAttributes();" from the declaration. It's useless since it'S a serialized variable and class so the Unity inspector will create the instance automatically. System.Serializable classes actually act more like structs ;)

Anyway you should see the changes in the inspector when you press play. Or when do you expect the changes?

edit
I've just tried your class and i see the changes when i press play. I'm not sure what behaviour you would expect...

Comment

People who like this

0 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 NukeImYourFather · Aug 13, 2012 at 01:49 PM 0
Share

Not sure what i was thinking yesterday :/ Anyhow, thanks a bunch. I never managed to get this far in my head :P

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C# | public variables in parent class should not show up in child class 1 Answer

Multiple Cars not working 1 Answer

Delegates with parameters 3 Answers

How do I use a function in a class more than once? 4 Answers

How can I access a function without knowing the script/class name to which it belongs? 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