- Home /
Instantiation happens three times, but called only once
This is something very peculiar. The following code will print this output:
"Sliderface Constructor 4"
"Sliderface Constructor 1"
"Sliderface Constructor 2"
"FROM NEW GUI"
"Sliderface Constructor 4"
Whereas I think It should output "FROM NEW GUI"
"Sliderface Constructor 1"
The GUI script is attached to only ONE GameObject, and (if I remove that component, all the output line disappear).
GUI script attached to a GameObject:
#pragma strict import System;
var ss_interface:SliderFace ;
function Start(){ // I have also tried with Awake() and SliderFace() Awake has no result, Sliderface Works the same way as Start
print ("FROM NEW GUI");
// AN interface containing sliders, aptly named SliderFace
ss_interface = new SliderFace();
}
// A separate file containing the class SliderFace (It is an User interface, and it uses sliders)
class SliderFace {
public static var sliderFaceCount :int =0;
function SliderFace(){
sliderFaceCount ++;
out ("Sliderface concstructor " +sliderFaceCount);
}
}
Answer by Mike 3 · Jul 22, 2010 at 09:27 AM
That seems to be a spectacularly insane javascript bug.
You can remove the ss_interface = new SliderFace(); line and it'll still create a few.
It seems to be something to do with how javascript is serializing the class, but anyways, to fix it:
@System.NonSerialized
private var ss_interface : SliderFace;
Thank You! I like your categorization of the Bug. File under : "Spectacularly Insane". This works.