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
3
Question by Brian-Kehrer · Jan 19, 2010 at 01:25 AM · iphoneserializationscriptableobjectstruct

Is it possible to serialize and store custom structs on the iPhone in scriptableObjects?

This is the general idea. I'd like to store a bunch of these in a scriptable object without making them classes. Unfortunately it fails to save the data when stored as a struct.

I've seen forum threads mentioning using custom inspectors, but those are not available in the iPhone IDE.

[System.Serializable] public struct Point{ public int x; public int y;

}

As a thought, if this IS possible in 2.6, how would one go about saving the data, and could that data be imported into iPhone Unity once serialized as an asset?

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 yoyo · Apr 04, 2014 at 12:20 AM 0
Share

Nope, Unity cannot serialize structs (on any platform).

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Duke · Jan 22, 2010 at 05:50 PM

Does it work correctly if you provide an ISerializable implementation?

using System.Runtime.Serialization;

[Serializable] public struct Point : ISerializable { public int x; public int y;

 public Point(SerializationInfo info, StreamingContext context) 
 {
     x = info.GetInt32("x");
     y = info.GetInt32("y");
 }

 void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
 {
     info.AddValue("x", x);
     info.AddValue("y", x);
 }

}

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 Brian-Kehrer · Jan 23, 2010 at 06:36 AM 0
Share

It doesn't seem to work for the iPhone. Thanks though.

avatar image numberkruncher · Jun 21, 2012 at 10:21 PM 0
Share

@$$anonymous$$$$anonymous$$ehrer In what way does this not work on iPhone for you? Is this working on other platforms?

avatar image numberkruncher · Jun 21, 2012 at 10:29 PM 0
Share

Doesn't seem to work at all for me...

avatar image whydoidoit · Jun 21, 2012 at 10:33 PM 0
Share

Everything on iPhone seems to have a problem with structs, it's something to do with the way that $$anonymous$$ono has implemented some of the CLR. There's a problem with SetValueDirect which doesn't help much. Better off to use classes I'm afraid - unless you are really stuck talking to some native interface.

avatar image SinisterRainbow · Oct 06, 2013 at 07:45 AM 0
Share

Unity states in their Serialization documentation to avoid structs, I also tried anyway :) but no go. See: http://forum.unity3d.com/threads/110247-Serialization-issues classes should work if impl'ing ISerialize

avatar image
1

Answer by andeeee · Jan 22, 2010 at 11:02 AM

Although structs don't give an error when they are marked as serialisable, they don't have the same behaviour as serialisable classes in Unity (properties visible in the inspector, etc). There might be some other approach, though. Are you using structs for better array or GC performance or is there another reason?

Comment
Add comment · Show 3 · 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 Brian-Kehrer · Jan 22, 2010 at 03:30 PM 1
Share

Yeah, better GC performance primarily. I would agree, but somehow Unity made Vector3 serializable, I wonder if the same method is possible? I've obviously switched to objects in the mean time, and the world hasn't ended yet, but in more performance critical sections of my code, this is at best annoying.

avatar image numberkruncher · Jun 21, 2012 at 08:31 PM 2
Share

Unity serialisation capabilities seem extremely under developed.

avatar image Stadob numberkruncher · Jan 17, 2018 at 10:07 AM 0
Share

2018 Still issue...

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Scriptableobject not saving if i force close the application. 1 Answer

Why do I need to serialize a struct inside a ScriptableObject to save its data? 1 Answer

If i force close my game the changes i made to my scriptable object are not saving. Is there anyway to get around this? 0 Answers

I have a class derived from ScriptableObject, and members are getting serialized when I don't want them to be. 1 Answer

Save EditorWindow to disk 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