DoNotSerialize

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

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.