Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 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
Add comment · 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? $$anonymous$$aybe 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
0
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
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 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.

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

Distribute terrain in zones 3 Answers

organize unity inspector with collapsable sections without using classes 1 Answer

Can't edit referenced class in the inspector 1 Answer

Accessing Normal Class from another class which derives from Monobehaviour 2 Answers

Why inpector keeps methods assigned when changed from public to private 2 Answers


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