- Home /
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 () {
}
}
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) ;
}
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
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.