Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Jan 18, 2016 at 05:50 PM by KnightRiderGuy for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KnightRiderGuy · Jan 17, 2016 at 08:43 PM · c#uigameobjectinspectorscene-switching

Object looses Inspector properties When Scene returns

OK this issues has been plaguing me for what feels like forever and no one seems to explain right what I need to do to fix the issue. I have a game object that when my scene changes it looses connection to items in the inspector when I return to the scene. I have tried this:

I added a video demo link to try and better explain what I mean. There must be a way of dealing with this issue?

 // Use this for initialization
     void Start () {
         StartCoroutine(OpenConnection());
         lightSlider = GetComponent<Slider> ();
         if(slider == null) slider = GetComponent<Slider>(); // search slider in this object if its not set in unity inspector
         if(source == null) source = FindObjectOfType<VoiceBox>().GetComponent<AudioSource>(); // search audiosource in this object if its not set in unity inspector
 
         }

Tos see if I could get the start function to re - assign the Audio course into the inspector but it does nothing when I return to my main scene.

Start inspector items intact Return inspector items missing

Here is a link to a demo video of what I mean Video Demo

screen-shot-2016-01-17-at-24108-pm.png (44.6 kB)
screen-shot-2016-01-17-at-24130-pm.png (51.2 kB)
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 hexagonius · Jan 17, 2016 at 08:46 PM 0
Share

do you mean while running the game or during editing?

avatar image KnightRiderGuy hexagonius · Jan 17, 2016 at 09:03 PM 0
Share

@hexagonius, Both, if I got to scene 2 and then return to scene one the objects in the inspector are missing, now just to be clear I do not want these items to carry across to scene 2 I just want them placed back when I return to scene 1.

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by KnightRiderGuy · Jan 18, 2016 at 05:46 PM

Turns out what I had to do was create an empty game object in my main scene that I call "DataHolder" and this object holds the references to the UI slider, AudioSource and UI text.

Then in my Init object on it's "Sending" Script I do this:

 void OnLevelWasLoaded (int level)
     {
         if (level == 2) {
             DataHolder stor = GameObject.Find ("DataHolder").GetComponent<DataHolder> ();
             //Variable names here
             source = stor.source;
             TemperatureText = stor.TemperatureText;
             slider = stor.slider;
         }
     }

That way when I come back to my main scene which is level 2 my "Init" object is repopulated with the references to the UI slider, AudioSource and UI text.

What a pain that was getting that information.

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 686InSomNia686 · Feb 03, 2016 at 04:48 PM 0
Share

Hi zentaiguy, So you have done a "safestate" of all your variable in an empty GO? I have also some problems of variable which become empty for no reason... Thanks, Clément

Follow this Question

Answers Answers and Comments

72 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why Does Prefab Loose UI elements on Scene Change 0 Answers

Move gameObject on UI Button Press 2 Answers

Revers Object Transfrom using an array problem in UI !! 0 Answers

GameObject.Find always returns null even when the object exists 1 Answer

Remember Toggle Button State When Scene Return 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