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 /
avatar image
0
Question by Arcana96 · Oct 12, 2016 at 01:21 AM · scene-loadingloadingscene-switching

Help with loading scenes

When I press the continue button on my main menu a script loads in and reads a file from the disk that stores the players position. When the script is loaded the script does what it's supposed to do and places the player in the position specified within the file.

However, after a second the player object will revert back to the position it is in the editor.

Is there something specific I have to do with the order of these things?

Comment
Add comment · Show 1
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 jrocamora · Oct 12, 2016 at 07:09 PM 0
Share

Is there a second player object in the new scene you are loading?

2 Replies

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

Answer by kingcoyote · Oct 12, 2016 at 10:49 PM

The most common culprit for data reverting back to an older state, or to a null/zero state, when the game starts, stops, or scripts are reloaded, is using variables that are not serializable by Unity.

When the Unity editor starts, it takes all GameObjects and serializes them, recreates them, and reapplies the serialized data. When the editor stops, the GameObjects are all cleared out and the serialized data is restored. This is to keep your game state as intended and to prevent playing the game from causing undesirable changes. Unity also does this serialize/recreate sequence if a script is reloaded during the game.

You can check to see what variables are serializable by Unity and try to stick to those value types, especially on public fields. I ran into issues with some GameObject data constantly being reset only to find that I was using a Dictionary, and that is not serializable. I ended up having to use a List that is converted to a Dictionary on Start, using one of the struct's properties as a key.

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 Arcana96 · Oct 12, 2016 at 11:10 PM 0
Share

I don't think that's the problem as I'm using a Vector3 and Quaternion which are definitely serializable. I set up another project and imported the same scripts and all seems to be working well there.

I did rewrite the way data was shared between scene change so maybe that was the issue. Thanks for the information, though.

avatar image
0

Answer by LZakhar · Oct 12, 2016 at 08:54 PM

Is there any default variables that can be set at/after loading process and somewhere on Update/FixedUpdete/LateUpdate etc. Position of your player resets to them? Silly but there ara so many little rocks. No way wanted to injure you. Did same mistakes by myself many times, and much more time then left to find and debug...

Comment
Add comment · Show 3 · 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 Arcana96 · Oct 12, 2016 at 10:40 PM 0
Share

Nah, I've looked a couple of times just in case. I can't see anything in my code that would revert the player position.

avatar image LZakhar Arcana96 · Oct 13, 2016 at 12:32 AM 0
Share

And so? the problem is still there? $$anonymous$$aybe some pice of code would help, but I don`t even emagine nedded place. Load/Start level? In my game levels loading from SQLite too, but all seems to be on their places.

And foolish question is loading going to game or to editor? For me as example there is some tools writen exclusive for editor, for easly level makenink, etc. If it is an Editor script and you dond use on DrawDefaultInspector() func OnInspectorGUI you need to use EditorUtility.SetDirty func. I remembered. In that hole I was once.

avatar image Arcana96 LZakhar · Oct 13, 2016 at 12:43 AM 0
Share

It was a problem with how my code was executing in Unity. I wrote a new script with more thought out logic. Thanks for trying to help :)

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

61 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

Related Questions

Scene loader Toutorial 0 Answers

Function deleting string by itself. 0 Answers

Loading screen with long-running CPU-heavy Awake() 1 Answer

Problems with Playerprefs script 1 Answer

Predfined Level Generation Procedural vs 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