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 Loyder · Mar 17, 2020 at 09:39 AM · serializationsave

Save System Problems

I wanted to have a save system and did everything like in the video:" SAVE & LOAD SYSTEM in Unity " from Brackeys But i get the error message in Unity : SerializationException: Type 'UnityEngine.Transform' in Assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable. System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers (System.RuntimeType type) (at :0)

Please Help :(

Comment
Add comment · Show 9
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 ShadyProductions · Mar 17, 2020 at 10:04 AM 0
Share

Share your code please

avatar image Loyder ShadyProductions · Mar 17, 2020 at 12:36 PM 0
Share

SaveSystem:

using System.IO; using UnityEngine; using System.Runtime.Serialization.Formatters.Binary; using System;

public static class SaveSytem { public static void SavePlayer (Spieler player) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/player.fun"; FileStream stream = new FileStream(path, File$$anonymous$$ode.Create);

     SpielerDaten data = new SpielerDaten (player);

     formatter.Serialize(stream, data);
     stream.Close();
 }

 public static SpielerDaten LoadPlayer()
 {
     string path = Application.persistentDataPath + "/player.fun";
     if(File.Exists(path))
     {
         BinaryFormatter formatter = new BinaryFormatter();
         FileStream stream= new FileStream(path, File$$anonymous$$ode.Open);

         SpielerDaten data = formatter.Deserialize(stream) as SpielerDaten;
         stream.Close();
         return data;
     }
     else
     {
         Debug.LogError("Save file not found in " + path);
         return null;
     }
 }

}

SpielerDaten:

using System.Collections; using System.Collections.Generic; using UnityEngine;

[System.Serializable] public class SpielerDaten { private Transform playerTransform;

 public float[] position;
 private Spieler player;

 public SpielerDaten (Spieler player)
 {
     playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
     position = new float[3];
     position[0] = playerTransform.position.x;
     position[1] = playerTransform.position.y;
     position[2] = playerTransform.position.z;
 }

}

Spieler:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Spieler : $$anonymous$$onoBehaviour { public void SavePlayer() { SaveSytem.SavePlayer(this); }

 public void LoadPlayer()
 {
     SpielerDaten data = SaveSytem.LoadPlayer();

     Vector3 position;
     position.x = data.position[0];
     position.y = data.position[1];
     position.z = data.position[2];
 }

}

avatar image metalted · Mar 17, 2020 at 01:03 PM 0
Share

A Transform is not a serializable class as the error message shows. So you can't use it for that purpose. You can check out this reddit post about the same question, where there is also a solution posted for this problem. https://www.reddit.com/r/Unity3D/comments/6h7t4x/question_on_serializing_a_list_of_transforms/

avatar image Loyder metalted · Mar 17, 2020 at 02:08 PM 0
Share

Sorry, but I dont get waht I have to change :(

avatar image metalted Loyder · Mar 17, 2020 at 02:43 PM 0
Share

If you look at the SpielerDaten script, you do it right for the position. You save the position in a float[] (which could probably just be a Vector3). This will work because that is a serializable type. In the same script you try to serialize a transform which is something you cannot do. You have to serialize the components of the transform: Position, Rotation and scale as Vector3's (or float[] if that is what you need or prefer). Then later when you need the data you can reconstruct the transform, using the Vector3's.

So it would look something like this: using System.Collections; using System.Collections.Generic; using UnityEngine;

 [System.Serializable] public class SpielerDaten { 
 
 public Vector3 position;
 public Vector3 eulers;
 public Vector3 scale;
  private Spieler player;
 
  public SpielerDaten (Spieler player)
  {
      Transform playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
      position = playerTransform.position;
      eulers = playerTransform.eulerAngles;
     scale = playerTransform.localScale;
  }
Show more comments

0 Replies

· Add your reply
  • Sort: 

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

134 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

Related Questions

Save/load playerprefs 2 Answers

Saving/Load using menu C# 1 Answer

Which types are actually serializable? Is the documentation incorrect or am I? 3 Answers

Error while saving game: SerializationException: Type 'UnityEngine.GameObject' in Assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable. 0 Answers

Strategy for saving game 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