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 primus88 · Jun 02, 2013 at 03:29 PM · scenerestart

Restarting scene not working properly

Hello,

I have a scene in my project. If I use my 'Restart' button to reload the scene, it works partially because there are many functions or variables that do not start again.

What to do do make restarting a scene behave like I would start it the first time ?

Comment
Add comment · Show 6
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 primus88 · Jun 02, 2013 at 04:30 PM 0
Share

That sucks.. Indeed the static variables fail to reset... Anyway I can hardcode that ? Telling them to reset ?

avatar image ExTheSea · Jun 02, 2013 at 04:37 PM 0
Share

Well there are two ways:

  1. Don't use static variables. Sometimes they are useful but they often make more problems then they help. They should only be used if really possible.

  2. Reset the necessary varibles in the OnLevelWasLoaded() function.

avatar image primus88 · Jun 02, 2013 at 04:40 PM 0
Share

Since there aren't too many, but they are referenced a lot, the second option sounds good.

Can you tell me, OnLevelWasLoaded() function, in what script (and where in the script) should be put ?

It should be the first script that the games starts to interpret ?

avatar image ExTheSea · Jun 02, 2013 at 05:27 PM 0
Share

You can put the OnLevelWasLoaded function in any script that exist from the start of the scene. So not one that is attached to a gameobject that's instantiated later.

It can be added like any other function:

Reference: http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.OnLevelWasLoaded.html

I'm gonna make one of my comments to an answer so that you can accept it to mark the question as solved.

avatar image primus88 · Jun 02, 2013 at 05:35 PM 0
Share

I have it connected to my main camera. Is it good enough ? I'm asking because it is still not working...

Show more comments

1 Reply

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

Answer by ExTheSea · Jun 02, 2013 at 04:12 PM

Normally if you reload a scene using Application.LoadLevel all function should work propery except of static function and static variables. They don't change when reloading the level as there is only one instance per class.

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 primus88 · Jun 02, 2013 at 06:23 PM 0
Share

Working perfectly without any need of OnLevelWasLoaded(). It seems by some beginners luck , I did set my static variables in the Start() function which seems to be enough :)

$$anonymous$$y problem was that I was setting time.scale to 0 when I was resetting the game and it was still set like this when the scene restarted.

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

15 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Unity 3d(Space) Questions 1 Answer

Scene changing 1 Answer

Reset The Scene ? 2 Answers

How to Set a bool to Individual Scenes (C#) 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