Using scriptable objects in the other half of the game project

hello,
can someone explain to me when to use scriptable objects and when not to?
you see im trying to creat a game where the player is a doctor that needs to treat patients in order to gain money, then use the mony to either buy a new office or hire someone or buy new equipment or upgrade an equipment…each equipment has a quality and this quality affects the difficulty of the mini games related to treating patients (patients data is stored using DB)…so my question is should I use scriptable objects or not? and why? I’ve already finished like 35-40% of the game…and now someone is telling me to use the scriptable objects…

And … ? Do you need ScriptableObjects?

If you don’t know, don’t use them. This is software engineering, not a cocktail party. :slight_smile:

Here’s how to reason about and use them:

ScriptableObject usage in RPGs:

Usage as a shared common data container:

2 Likes

i wasn’t planning on using SOs since im reading and storing data on a DB…its a collage project and on of my teammates wants to use them…so i dont wanna argue if its best to use them instead of DB.

so we use SO for game saving? i understand its better to use for unity inspector for value tuning and for game settings…but im not really sure if its the right thing for my game…sry im new to SO iv never really used them​:sweat_smile::slightly_smiling_face:

That’s exactly what ScriptableObjects are for, as noted in the above links.

Use ScriptableObjects to author game data easily in the editor.

If you prefer to author your game data in a “DB,” whatever form that takes, that’s up to you. Just make VERY sure that this so-called “DB” plays nice with Unity, as many of them don’t, or they work on one platform but not the other, etc.

I use ScriptableObjects because they “Just work” in Unity and they are first class citizens there.

If by “game saving” you mean loading / saving progress by the user, then NO, ScriptableObjects are NOT suitable for that. Here’s more reading:

Load/Save steps:

An excellent discussion of loading/saving in Unity3D by Xarbrough:

And another excellent set of notes and considerations by karliss_coldwild:

Loading/Saving ScriptableObjects by a proxy identifier such as name:

When loading, you can never re-create a MonoBehaviour or ScriptableObject instance directly from JSON. Save data needs to be all entirely plain C# data with no Unity objects in it.

The reason is they are hybrid C# and native engine objects, and when the JSON package calls new to make one, it cannot make the native engine portion of the object, so you end up with a defective “dead” Unity object.

Instead you must first create the MonoBehaviour using AddComponent() on a GameObject instance, or use ScriptableObject.CreateInstance() to make your SO, then use the appropriate JSON “populate object” call to fill in its public fields.

If you want to use PlayerPrefs to save your game, it’s always better to use a JSON-based wrapper such as this one I forked from a fellow named Brett M Johnson on github:

Do not use the binary formatter/serializer: it is insecure, it cannot be made secure, and it makes debugging very difficult, plus it actually will NOT prevent people from modifying your save data on their computers.

A good summary / survey of the problem space:

1 Like

thank you very much​:smile: , you’re the best !:ok_hand: