• 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
1
Question by iMugen · Aug 31, 2012 at 11:27 PM · serializeserializable

Type UnityEngine.GameObject is not marked as Serializable.

I'm having trouble with these classes. Is it not possible to serialize custom types? It was working fine before when I was testing with just the Class1 Class, but after finishing the script with all the Classes I need I can't seem to serialize these custom types. They all inherit from BaseClass which just holds some variables all the classes share, and are very similar like the examples below. I use a SaveData class that holds the variable info and constructor, and a SaveLoad class that does the serialization saving and loading- both of which had been working without a hitch 'til now. Error occurs while trying to save to path name.. If I need to provide more information please inform me. Thank you.

 using UnityEngine;
 using System.Collections;
 [System.Serializable]
 public class BaseClass{
     public string name;
     public int level;
     public int NRGcost;
 }

 [System.Serializable]
 public class Class1: BaseClass{
     public int bNumb;
     public float sTime;
     public GameObject[] alls;
     
     public void LevelUp(){
         level += 1;
         if(level == 2){
             NRGcost = 50;
             bNumb = 3;
             alls = new GameObject[bNumb];
             sTime = 8.0f;
         }
         if(level == 3){
             NRGcost = 150;
             bNumb = 4;
             alls = new GameObject[bNumb];
             sTime = 10.0f;
         }
     }
     
     public Class1(){
         NRGcost = 0;
         level = 1;
         bNumb = 2;
         alls = new GameObject[bNumb];
         sTime = 6.0f;
         name = "Class 1";
     }
 }
 [System.Serializable] //<<Gives error: SerializationException: Type UnityEngine.GameObject is not marked as Serializable.
 //>>taking it out gives error : Type Class2 is not marked as Serializable.
 //but nothing about Class1.
 public class Class2: BaseClass{
     public GameObject pow;
     public float pTime;
     public string pName;
     
     public void LevelUp(){
     }
     
     public Class2(){
         NRGcost = 0;
         level = 1;
         pTime = 7.0f;
         name = "Pow";
     }
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Kryptos · Sep 01, 2012 at 10:50 AM

GameObject is not a base type and cannot be serialized. You cannot save GameObject outside of Unity.

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 iMugen · Sep 01, 2012 at 10:29 PM 0
Share

Thank you, can't believe it was staring me in the face.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

Non-static Singleton implementation 1 Answer

Saving Non-Prefab Data During Editor Play 0 Answers

Save and Load all spawned objects in their position using array 1 Answer

Private Variables Serialised By Default 2 Answers

Serialized data show information after load 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