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 Danta1st · Apr 22, 2012 at 11:09 PM · editorclassstruct

Problems with editing a class from the editor

Hello I'm toying around with a class called turbine and, say i wanna make different turbine models, and edit the values of those from the editor. I've managed to figure out a solution like in the code, but somehow the values i give doesn't stick once i run the program/script. it seems that the values return to zero/default when i run.

Initially i just wanted to make it a struct, but i read something about those not being able to being set from the editor. If anyone can provide a workaround for this it would be appreciated.

 using UnityEngine;

using System.Collections; //using System.Serializable;

public class turbines : MonoBehaviour {

 [System.Serializable]
 public class turbine{
     public string model;
     public int lifetime;
     public float height;
     public int ratedWind;
     public int cutinWind;
     public int cutoutWind;
 }
 /*
 public struct turbine{
     public string model;
     public int lifetime;
     public float height;
     public int ratedWind;
     public int cutinWind;
     public int cutoutWind;
 }*/
 public turbine V10018MW;
 
 // Use this for initialization
 void Start () {
     V10018MW = new turbine();
     Debug.Log(V10018MW);
 }
 
 // Update is called once per frame
 void Update () {
 
 }

}

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

1 Reply

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

Answer by Lo0NuhtiK · Apr 22, 2012 at 11:38 PM

My guess is that it's resetting because in start you say V10018MW = new turbine and then don't give it any values??? It already has it's values when you declare public turbine V10018MW.

give this a run->

 void Start () {
    turbine X1 =  new turbine() ;
    X1.model = "X1 : TEST new Turbine model Value = this string" ;
    Debug.Log(X1.model) ;
    turbine X2 = V10018MW ;
    Debug.Log("X2 turbine model value = " + X2.model + " : Which is the same as V10018MW model value of = " + V10018MW.model) ;
    Debug.Log("---V10018MW---");
    Debug.Log(V10018MW.model);
    Debug.Log(V10018MW.lifetime);
    Debug.Log(V10018MW.height) ;
    Debug.Log(V10018MW.ratedWind) ;
    Debug.Log(V10018MW.cutinWind) ;
    Debug.Log(V10018MW.cutoutWind) ;
 }
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 Danta1st · Apr 23, 2012 at 07:20 AM 0
Share

thx. This helped. just deleted the ' V10018$$anonymous$$W = new turbine();' line and it worked. Guessing thats what i get for doin' this sort of stuff at the late hours xD

avatar image syclamoth · Apr 23, 2012 at 07:27 AM 1
Share

Close. The problem is that every time you go

 V10018$$anonymous$$W = new turbine();

it overwrites the existing saved values with the default ones! So, all that effort you went to to make sure the values would be saved just gets completely ignored.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Accessing a UnityEditor class. 1 Answer

Variable updating itself or not (ex: Transform vs Vector3) 2 Answers

How to serialize an array of classes 1 Answer

Conversion of a static class to struct? 1 Answer

CustomEditor show an instance of a Class inside a Class 0 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