I’ve been working on my project for a while. Yesterday, i found out (thanks to Kurt-Dekker) that you can’t use System.IO; for accessing the assets multiplatform-wide. I was advised to use a public field instead or use Resources.Load<T>(); instead, which i’m glad to know. However, it also made me think if the code snippet that currently uses System.IO needs to be there in the first place and if maybe, its functionality could be replaced with Scriptable Objects. Currently i don’t have much in my project other than some UI scripts, List deserialization and few assets so i decided to ask for an advice before going any further.
Allow me to explain what i had in mind:
My project contains such UI elements as toggles, buttons being a part of the gameplay. For example, i have a grid list of buttons which i want to output the values assigned to them on OnClick() event according to the button that has been pressed. This list is populated dynamically.
My original intent was to “connect” the populated buttons with a data model that would take its values from a deserialized JSON List() and output/pass those values to whatever script i’d want it to (for example, spawn the character models/sprites script, make them do things script, etc). While it’s a very logical thing to do, the biggest disadvantage that i see right now is that it’s not flexible at all and i’d have to create multiple copies of what essentially could be one set of objects used across the entire project. And the more i think about it the more i realize how cumbersome the entire thing is and a feeling that i could’ve done it in a much easier way does not leave me whatsoever.
And now, allow me to explain what i think i could possibly make with Scriptable Objects:
I want to have two sets of SO’s. I want Scriptable Objects to serve as a one and only asset that can be re-used multiple times and be easily instantiated. One set of my Scriptable Objects would contain:
the characters info (health, ID, action points (defense/attack)).
the characters sprite/a reference to it?
maybe a 3d model/a reference to it?
and be able to be used wherever i want them to be used. I also want some Scriptable Objects to be essentially ready-to-instantiate complete Buttons, with an icon and outputting stats on Click. Those would be a second set containing:
the characters info (health, ID, action points (defense/attack)).
the characters icon.
the definition for this set of SO’s that makes them Buttons.
While i understand it all might be a bit confusing, feel free to ask for any additional clarifications on my projects intents.
try, fail, reflect, retry, there is no better way.
Most likely you will need to meet halfway on both methods.
You will need System.IO for data persistence, for all the stat sounding stuff like health, atk, def, and more.
You will need ScriptableObjects for project linkages, or at least I assume so for what you might attempt.
Thanks for your answer, Laperen! I was under the impression that i could simply stuff everything i need into SO’s and avoid using any MonoBehaviours for storing any character related data.
Unfortunately i can’t use System.IO, because i want my project to be multiplatform.
If i wasn’t clear, what it all essentially boils down to is me wanting to use SO’s as a unified visual+data asset in order to not use MonoBehaviours for data storage and save both memory and time, as well as have an easier path for further improvments upon the gameplay.
I’ve seen your other thread so I know where this thought stems from. You are mistaken, what your replier was referring to, was grabbing stuff from the Assets folder(excluding anything in StreamingAssets) in the project with System.IO.
If you are grabbing any files you have created for yourself(usually binary or some form of text file like .json), System.IO is perfectly fine, caveat being that different platforms have different preferred paths and directories to put game save data.
And regardless, ScriptableObjects do not hold persistent data. In build, the values will revert to their default values, the values they had on build, when the game starts. You will still need to use System.IO to save persistent data on disk nomatter what.
Nobody knows if ScriptableObjects will be a good fit for your project, you are asking for an opinion which usually ends in less than civil discussion. The most optimistic thing you can expect is everyone mentioning the good and bad of each method, and you evaluating which method you want. Without first hand experience in any method however, this evaluation will be flawed.
The best thing you can do is to implement what you think is best at the moment, seek specific advice using that attempt, most likely find out what you can do better or differently, and attempt it again. If you are desperate for time, this will be even more essential, since you need to get answers quickly. The only way to get answers quickly is to be specific with your questions, and the only way to do that is to attempt quickly.
That’s exactly the type of response that i expected to recieve! Thanks for clarifying the assets part. If the only “problem” with System.IO is having to set a different path to a file, then it’s no biggie and i’m very happy to hear that it’s not going to be a problem.
Yes, now that i’ve re-read my post, i realized that while it seems like it supplies enough information to help understand my creative intent, it still is too vague in its nature to really provide a basis for a definite answer. I think i’ll try to simply ask about the pros and cons of whatever i need an advice on rather than generalizing or at least giving a much more narrow scope (e.g what is a a common reliable way to save player data, what are the ways to do something).
Thank you again for your answer! I’ll leave the thread title to “Feedback” for a while so i can get more input on the question.
I don’t want to make an extra thread for what is related to the same question, so i’ll ask it here.
I read in Unity’s introduction to SO’s that
Some things in my project are only going to have values that are not going to change (for example some buttons that i have i want to have as assets with both visual data (a sprite) and string/int values). Are SO’s a good choice for that case?
The reason why the documentation says ScriptableObjects is for unchanging values, is because of how they behave in a built game. In a built game, ScriptableObjects revert to their default values when the game is started. During the game session, you can happily change the ScriptableObject values to whatever you like if need be, but come the time to quit the game, the ScriptableObject values will be back to default values the next time the game is started.
The default values of a ScriptableObject are the values it had when the game was built. In Editor, it feels like data persistence with ScriptableObjects because the game has not been built, so changes are kept after editing, which is not entirely the case for a built game.