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
1
Question by Jens T · Jul 22, 2010 at 08:53 AM · objectinstantiationconstructor

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);

 }



}

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
2
Best Answer

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;
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 Jens T · Jul 22, 2010 at 09:34 AM 0
Share

Thank You! I like your categorization of the Bug. File under : "Spectacularly Insane". This works.

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

No one has followed this question yet.

Related Questions

Is it necessary to assign the result of Instantiate() to a variable and is there a need to always typecast? 1 Answer

AndroidJavaObject Builder Class 1 Answer

Getting error BCE0024, while the constructor exists 1 Answer

Creating multiple rays/objects based off of a variable? 0 Answers

Getting all Object to go next scene. 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