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 vtchom3 · Jul 09, 2019 at 05:50 PM · unity 5errorload

My player figure falls down after load

I tried to find this error, but I was unsuccesfull. You can see on youtube video, that my character falls down after load. https://youtu.be/_CKNaYBxvhQ?t=1

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 vtchom3 · Jul 10, 2019 at 01:35 PM 0
Share

here is save and load script

     public void Save()
     {
         BinaryFormatter bf = new BinaryFormatter();
         FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat");
 
         PlayerData data = new PlayerData();
         data.x = transform.position.x;
         data.y = transform.position.y;
         data.z = transform.position.z;
 
         bf.Serialize(file, data);
         file.Close();
     }
 
     public void Load()
     {
         //Scene$$anonymous$$anager.LoadScene("enfos");
         if (File.Exists(Application.persistentDataPath + "/playerInfo.dat"))
         {
             BinaryFormatter bf = new BinaryFormatter();
             FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", File$$anonymous$$ode.Open);
             PlayerData data = (PlayerData)bf.Deserialize(file);
             file.Close();
 
             Vector3 tempPos = transform.position;
 
             //GameObject go = GameObject.Find("Player");
 
             tempPos.x = data.x;
             tempPos.y = data.y;
             tempPos.z = data.z;
             transform.position = new Vector3(data.x, data.y, data.z);
             //transform.position = tempPos;
         }
     }
 
     public delegate void SerializeAction();
     public static event SerializeAction OnLoaded;
 
     void OnEnable()
     {
         //        Debug.Log("PrintOnEnable: script was enabled");
         Load();
     }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by I_Am_Err00r · Jul 10, 2019 at 01:53 PM

To help you debug, try logging the Vector3 position on close so you can see what it says and then compare that with the load values, make sure they match.

Just looking at it though, what is this line of code doing when you have these:

            Vector3 tempPos = transform.position;
  
              //GameObject go = GameObject.Find("Player");
  
              tempPos.x = data.x;
              tempPos.y = data.y;
              tempPos.z = data.z;
              transform.position = new Vector3(data.x, data.y, data.z);


why do you have Vector3 tempos = transform.position, and then assing each x,y,z value based on it, then assign transform.position the values you just created based on it originally?

Comment
Add comment · Show 5 · 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 vtchom3 · Jul 10, 2019 at 04:19 PM 0
Share

tempos is only old try to set coordinations can bě deleted works same

debug Save and Load are same coordinations after Load figure falls down from the box

     public void Save()
     {
         BinaryFormatter bf = new BinaryFormatter();
         FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat");
 
         PlayerData data = new PlayerData();
         data.x = transform.position.x;
         data.y = transform.position.y;
         data.z = transform.position.z;
 
         bf.Serialize(file, data);
         file.Close();
     }
 
     public void Load()
     {
         //Scene$$anonymous$$anager.LoadScene("enfos");
         if (File.Exists(Application.persistentDataPath + "/playerInfo.dat"))
         {
             BinaryFormatter bf = new BinaryFormatter();
             FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", File$$anonymous$$ode.Open);
             PlayerData data = (PlayerData)bf.Deserialize(file);
             file.Close();
 
             transform.position = new Vector3(data.x, data.y, data.z);
             //transform.position = tempPos;
         }
     }
 
     public delegate void SerializeAction();
     public static event SerializeAction OnLoaded;
 
     void OnEnable()
     {
         //        Debug.Log("PrintOnEnable: script was enabled");
         Load();
     }
avatar image I_Am_Err00r vtchom3 · Jul 10, 2019 at 05:09 PM 0
Share

So you are saying that the coordinates are the same on save and load, how about logging during update to see if they move any from there? There wouldn't be any way that the positions would be exactly the same if on the save they are standing on top of something and the load they are not; the only reason that would occur is if somehow the level is moving slightly between saves and loads (but even then, the y coordinates at the least would be different from the drop in height).

avatar image vtchom3 I_Am_Err00r · Jul 10, 2019 at 06:40 PM 0
Share

Coordinates on Save and Load are same. After Load something happens what drops my figure down.

Show more comments
avatar image vtchom3 · Jul 13, 2019 at 08:10 PM 0
Share

How to log position of player in Update?

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

228 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 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 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 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

unity fontainebleau importing error 0 Answers

Legacy Animations and Unity 5 - What's The Deal? 1 Answer

Unity 5 fatal error 3 Answers

Unity 5 crash on startup 1 Answer

EXC_BAD_ACCESS (SIGABRT) from Unity::Material::CreateMaterial 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