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 Alavardo · Jun 15, 2011 at 08:37 AM · arraysaveinventorysaveload

Error when trying to save inventory with array.

I am using http://www.unifycommunity.com/wiki/index.php?title=Save_and_Load_from_XML to save and load.

i have an inventory with array. That is class that contains items vars. This form Inv_Inventory from Player:

 class InventoryItem
 {
 
     var worldObject: GameObject;
     var itemIcon: Texture;
     var itemName : String;
     var itemDescription : String;
     var Stack : int;
     var MaxStack : int;
 
 }

This From SaveLoad:

  if (GUI.Button(_Save,"Save")) {
             
       GUI.Label(_SaveMSG,"Saving to: "+_FileLocation);
       //Debug.Log("SaveLoadXML: sanity check:"+ _Player.transform.position.x);
       var plr = gameObject.Find("Player");
 var invScrpt = plr.GetComponent(Inv_Inventory);
 
       myData._iUser.x = _Player.transform.position.x;
       myData._iUser.y = _Player.transform.position.y;
       myData._iUser.z = _Player.transform.position.z;
       myData._iUser.name = _PlayerName;   
       
         for( var j = 0; j < myData._iUser.inventory.length; j ++ )
     {
         for( var s = 0; s < myData._iUser.inventory[j].length; s ++ )
         {
       
       for( var i = 0; i < invScrpt.inventory.length; i ++ )
     {
         for( var k = 0; k < invScrpt.inventory[i].length; k ++ )
         {
         if (invScrpt.inventory[i][k] != null)
         {
         myData._iUser.inventory[j][s] = invScrpt.inventory[i][k];
         }
         }
     }
     }
     }
       // Time to creat our XML!
       _data = SerializeObject(myData);
       // This is the final resulting XML from the serialization process
       CreateXML();
       Debug.Log(_data);
    }

Like That i am trying to save Inventory Array to file.

But when i click save and have item in inventory i have this error.

InvalidOperationException: The type of the argument object 'Inv_Inventory.InventoryItem' is not primitive.

Help me plz guys. I don't know what to do.

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
0

Answer by Ricardo Arango · Jun 15, 2011 at 11:56 AM

You can only serialize primitive types directly. If you are not using Primitive types you should implement the ISerializable attribute with the methods used for serialization.

Have a look at the ISerilizable docs to understand this a bit better:

http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iserializable.aspx

In you code the InventoryItem class is not serializable. And some of the members of the class are not either (GameObject or Texture)

Comment
Add comment · 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

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

2 People are following this question.

avatar image avatar image

Related Questions

SerializationException: Type UnityEngine.Vector3 is not marked as Serializable. 1 Answer

Save an array to file 1 Answer

Checking if items are present in array of list, how to do it? 1 Answer

How to save my settings 1 Answer

multiple rows, in an array in C# 2 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