Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by raycosantana · Oct 04, 2013 at 11:09 AM · gameobjecttexture2dserialization

can texture2D and GameObject be serialized?

Its there any way to serialize Texture2D and gameobjects? Ive created an inventory system that uses them (one is the Icon and the other is the particles that get instantiated when the Item is used) but when I attempt to save the data using binaryformatter I get serialization exception error saying that texture2D its not market as serializable (or GameObject); here is the Item class I use:

 using UnityEngine;
 using System.Collections;
 [System.Serializable]
 public class IItem  {
   // classes that implement Item should define this method
   public string Type;
   public string name;
   public int Cantidad;
   public Texture2D Icon;
   public int Value;
   public GameObject Particles;
     public IItem(string newName, int newCantidad, Texture2D newIcon, int newValue, GameObject newParticles, string newType){
         name = newName;
         Cantidad = newCantidad;
         Icon = newIcon;
         Value = newValue;
         Particles = newParticles;
         Type = newType;
         
         
     }
 }

Thanks in advance!

Comment
Add comment · Show 5
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 whydoidoit · Oct 04, 2013 at 11:39 AM 0
Share

Not much hope of doing that with Binary Formatter - check out EZSave or my free Unity Serializer that handle this kind of thing for you. Not always straightforward though of course, serialization is a tricky subject.

avatar image raycosantana · Oct 04, 2013 at 12:08 PM 0
Share

I see, I already tried your Serializer once but I decided to do this game without any kind plugins and code everything on my own; what I will do is remove the textures and the gameobject from this class and add every posible texture and gameobject in the inventory class, it seems like a messy solution but in fact there aren't that many Items and many of the gameobjects (which are particle emitters) are reused between items (for example all the potion items use the same particle emitter); thanks!

avatar image raycosantana · Oct 04, 2013 at 12:38 PM 0
Share

Will try that, thanks!

avatar image AntFitch · Jan 25, 2014 at 12:49 AM 0
Share

At least for the texture2D, perhaps you save the path+name? Then when you need to load the texture, you use path+name to re-attach your texture to your gameobject?

avatar image OP_toss · Jan 25, 2014 at 01:20 AM 0
Share

Unity's classes are blackboxed, so we can't adjust their serializability, or write wrapper classes to add our own.

So what you need to do is create an extension class, that adds serialization methods to your classes. Save everything you need to reinitialize the object back exactly how it was. Then reinitialize everything in your deserialization methods. The cleaner you set up your serialization/deserialization, the better. It's super nice once they are in place, especially for multiplayer games (if you're serializing to text).

$$anonymous$$eep in $$anonymous$$d there's quite a bit to save for a gameobject (name, tag, trans.locpos, trans.locrot, trans.locscale, trans.parent, layer). Try not to miss any of the tiny vars.

Please post it here when you're done! I'd love to use it myself!

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

20 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

Related Questions

Object Placement alignment to background image 2 Answers

Implementing GetComponent or accessing children from SerializableObjects 1 Answer

GameObject HideFlags.DontSave not working as expected 1 Answer

Better way for a tile based system 0 Answers

How to get mipChain and linear values from existing Texture2D 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