>
Hi guys,this may be a little of topic because it is about a function of asset but maybe you guys can help me.It may also be a function of unity.
I have a problem,
I am using a Unity Serializer asset for saved games,it say's here that
You also want to think “Are there things that shouldn’t be saved?” if the answer is yes then you want to add a DoNotSerialize attribute in front of each of those. You can also add this to a class and it will never be serialized, even if variables that hold instances of it say they can be.
You can specify that a particular behaviour should not be saved by adding a DontStore attribute to the class.
You can specify that all public properties should not be saved by using a [DoNotSerializePublic] attribute and then override particular fields or properties with [SerializeThis].
So in my list,I have a public Texture that cant be saved for some reason and if i load my save games the texture will dissapear so i need it to not touch the public texture so i added this.[DoNotSerialize]
[System.Serializable]
public class Buyable
{
public string name;
[DoNotSerialize]public Texture2d Chartexture;
public int Cost;
public int number;
public bool Unlocked;
public Texture2D Unlockedtexture;
public string Unlockedname;
}
But it still Serializing so i think i am misunderstanding it.If anyone knows how to fix this please reply.thanks
Answer by kurotatsu
·
Sep 16, 2014 at 05:53 AM
texture2d, and gameobjects can't be serialized or saved, or deserialized and loaded.
Consider making a seperate list of your textures of all your Chartextures, then use an int for it's position in the list that you can save in buyable, then load it separately afterwards based on it's id.
This is basically what I'm doing in this Link, my items class has textures and gameobjects, so I grab the info I need and save it separately, then reload and apply it as needed using vexes method:
I'm currently writing a itembox/merchant asset to sell on the asset store, so this knowledge is VERY usfull.
I have 2 list that both contain an int.I want to compare the int in List 1 to the int in List 2.And if they're the same then i want the texture2d in list 2 to be the texture 2d in list 1.Can anyone ple give me an example script i am looking for.Thanks
Unity Serializer can serialize Textures and GameObjects, not directly maybe, but nevertheless the references are stores and can be loaded without any problems.
For Materrials, you might have to manually add some material properties into the relvant US script, it is explained somewhere on the US user.
Serialize class with generic Dictionary that holds custom class objects
1
Answer
Unity doesn't store GUID field?
2
Answers
Set Dirty on class instance?
0
Answers
Photon Custom Serializer Help
1
Answer
Call SaveGame() when application loses focus?
2
Answers