Saving/Loading Materials & Objects at Runtime

Hello I have a Unity Game with a store where players can customize their skins (material) and objects such as hats, shoes, etc...

I had tried using JSON serialization to save these objects/ materials... this works within the editor, but when I deploy to iOS and test on a device, the material/objects do not load despite the application retrieving the correct JSON string. What is even weirder however, is that if I navigate to the store scene where all of these objects and materials are contained, then the saved skin/object load properly (despite the JSON string never changing).

In Unity when I save the material or object as a JSON string it saves as skin: (InstanceID: 34567)
On iOS it saves as skin: (m_FileID: 3456, m_PathID: 0) , where path id is always 0.

Rather than look for a fix I think I am going to change how I save the skin/objects. I am wondering what is the recommended way of doing this. It seems that JSON is suited better to primitives, not objects.

Another alternative is Resource.Load, I do not believe this will suit my needs because the Resource folder can not be modified at runtime. Perhaps I could move all of the store objects/skins into the resource folder ahead of time? This is a lot of data however.

If anyone can point me in the correct direction I would appreciate it!

There's a lot of this question being asked lately. I'll just link what I posted five minutes ago:

https://forum.unity.com/threads/saving-tilemap.1389024/#post-8744931

In your case you would need to get the pixels of any customized textures written. This could mean converting them to JPG or PNG and writing them, or else getting all the pixels into an array and adding it to your data.

[quote=“Kurt-Dekker”, post:2, topic: 906598]
There’s a lot of this question being asked lately. I’ll just link what I posted five minutes ago:

https://forum.unity.com/threads/saving-tilemap.1389024/#post-8744931

In your case you would need to get the pixels of any customized textures written. This could mean converting them to JPG or PNG and writing them, or else getting all the pixels into an array and adding it to your data.
[/quote]

I ended up creating a gameobject which has a script that has a serialized material, texture, and gameobject array. These contain all of the possible materials, textures, and objects that could possibly be bought in the store (which are already contained in my project anyway).

Then I save the names of the equipped materials in a JSON file. Then when I need to load the character (hats, shoes, skin) I just retrieve the name of the object/material/texture from the gameobject I mentioned before.

The only issue with this is that I have this object which persists through my scenes, which contains all of this serialized fields. I have called DontDestroyOnLoad on it. It does not effect performance on iOS devices tho. I have considered instead putting all of these materials, textures, and objects into the resource folder. If I run into issues I will probably try that.

NICE! Well done Angel.

It does that... so yeah, it might be a bit heavy on memory, but if you can handle it, USE the memory!

It also means there will be less or no load times or load "lags" for you!

This would work equally well, since you already have it as names. Just be sure when you load:

Always use Resources.Load<T>(), never use Resources.Load() as T

https://discussions.unity.com/t/847547/4

And the same goes for Resources.LoadAll<T>()

Generally you want to avoid writing code that is simply waiting to mysteriously fail simply by the future appearance of an identically-named file of a different type.

[quote=“Kurt-Dekker”, post:4, topic: 906598]
NICE! Well done Angel.

It does that… so yeah, it might be a bit heavy on memory, but if you can handle it, USE the memory!

It also means there will be less or no load times or load “lags” for you!

This would work equally well, since you already have it as names. Just be sure when you load:

Always use Resources.Load<T>(), never use Resources.Load() as T

https://discussions.unity.com/t/847547/4

And the same goes for Resources.LoadAll<T>()

Generally you want to avoid writing code that is simply waiting to mysteriously fail simply by the future appearance of an identically-named file of a different type.
[/quote]

Thank you for your input…It would be nice to have someone I can talk to about thiss stuff if you would want to exchange info ? angeldevsoftware@gmail.com