ScriptableObjects "save memory" How?

Well what do you think is more memory efficient: Every material having a reference to that one single texture, or every material having its own unique copy of that texture? The first is the allegory for referencing a ScriptableObject and the latter would be the Prefab.

So the savings are in things like default types and common components, and that’s about it?

If so, don’t Prefab Variants provide this same benefit, with the addition of adding additional GameObjects and Components, too?

I honestly don’t know why you keep bringing other things into it. The savings are in the memory allocated per instance of each active object.

If you have 1,000 Monsters with 1,000 integers: you create 1,000,000 integers or 4 million bytes.

If you have 1 ScriptableObject with 1,000 integers and have 1,000 Monsters that reference that 1 ScriptableObject: you create 1,000 integers and 1,000 references which is 8,000 bytes.

Exactly, default types. Which are small, generally speaking.

I get that. But those savings are going to be trivial, in most instances (excuse the pun) because most normal game prefabs are going to have very few values, and need local storage for most of them, that can also serve as default storage and setters during editing, and reference a game manager for any defaults needed after they’ve changed during gameplay.

1 Like

Nothing new brought into it. Prefabs Variants are part of the prefab workflow. And they have, as I mention, additional benefits, which are (quite frankly) immense.

If Prefab Variants each use their own storage memory for what’s common to them in their parent prefab, as opposed to only Overrides and Additional GO and Components using unique storage, then I can see one example of a possible benefit (involving much more work and loss of creative freedoms) to Scriptable Objects, in terms of storage space but this won’t reduce RAM needed for instances.

If you understand, and have understood from the beginning, what’s really the point of this thread? If you don’t want to use them, don’t. No one’s forcing you to use one architectural strategy over another. The strategy of sharing common data has a demonstratable effect on memory consumption, and those savings could be significant or even essential depending on the hardware you’re targeting or the scope of a project.

Prefab variants have no bearing on the discussion because they’re only relevant to the editor and are regular GameObjects with buckets of data at runtime.

I don’t understand your hostility. These are sincere questions.

When many make claims about memory usage being less, I presumed (perhaps wrongly) that this must be significant and obvious memory savings. It seems, from what’s been put forth so far, that’s not the case.

If you can’t see the workflow similarities between a Prefab Variant’s relationship with the Prefab it derives from and a Prefab’s potential relationship with, and reliance upon, a ScriptableObject, as per this question of memory savings, perhaps you haven’t used Prefab Variants.

It’s smaller regardless of if your use of them is trivial.

It isn’t to say that prefabs should be avoided.

It’s to say use the tool that best fits what you are needing to do.

A ScriptableObject can serve many purposes. One of them is to share immutable data across multiple instances to reduce the memory footprint of that data.

Give you an example where the savings is very high.

Say you have some prefabs that need to know what inventory items exist (maybe it’s mobs for a region that on death drop an item by some odds). You could just have an array on the “ItemDrop” script that you fill with the items. Meaning every mob has a copy of this array. And if this array is large… and you have a large number of mobs. This can end up taking up a lot of memory (similar to the texture example from before).

But if it was in a scriptableobject that each mob referenced. Then it’s just one single array that is referenced by every mob.

Reduced memory.

You can believe that trivial… but it’s still reduced.

And if you multiply this by the multiple times you do this, this can be significant… depending what you define as significant. In the end graphical data is going to be far more memory intensive than this sort of data just because of the nature of things. So at the end of the day it may only end up being a 1% savings if your game is graphically bloated. But for some people that 1% may actually be significant if it is what stands between them and release.

Now it comes with implications though… it means every mob has the same exact pool of inventory items that it can drop. If you want distinct item drops per mob you’d have to create the distinct pools of items for each category of drop. Thus reducing the benefits of the memory. BUT that only applies if your game is a game where each mob has a distinctly unique set of items that it drops from.

On the flip side. Say your game is a completely different design where a region has a static number of items that can be dropped regardless of which mob it is. As a mob drops some item, it is no longer available to be dropped by another mob. This is something the shared scriptableobject could benefit since it COULD be used to store that mutable value (what items were consumed).

It all comes down to what YOU need for YOUR game and understanding the implications of the design choices you made.

Cause mind you < memory isn’t necessary important if it doesn’t help you make the game you want to make. BUT if it is critical to your game that you reduce some memory footprint because the benefits of distinct lists per prefab is not beneficial to the game, but the lower memory overhead is because say you’re targeting mobile or something… then it is.

It’s up to your needs.

(and mind you this is only one feature of scriptableobjects. And technically speaking a prefab could be used in a similar manner. Where your prefab for you mob references a shared prefab of the inventory items. Back in olden times when SOs didn’t exist. We just used prefabs like this. But it came with weird caveats and annoyances arising from the ambiguity of prefabs from actual instances of those prefabs).

In the end though if this is not adequate to your concept of significance.

Well… we didn’t claim that SO’s saved all that much memory. We’re just demonstrating HOW it can save memory.

The unnamed “presentations” and “talks” are who you may want to take your semantical gripes about the significance of memory savings. Maybe they exaggerated it, maybe you misinterpreted it, there’s no way for us to actually know since it’s an unnamed source you didn’t offer up.

It’s to the point where it’s EVERYONE that mentions ScriptableObjects, as though it’s a mantra that must be ushered when talking about ScriptableObjects.

All Hail The Memory Savings of ScriptableObjects.

To the rest of your writings.

Thank you!

Will digest and attempt to wrap head around.

More stupid questions will likely follow. Pre-emptive apologies.

THANK YOU!

I had wrongly envisaged that the savings must be more significant, and that I simply didn’t see or understand where or how that significant saving was occurring, considering the desire to mention this aspect of using ScriptableObjects by everyone promoting their usage.

You’re right, there’s many other reasons to use them, only some of which I grok. I am at an inflection point, trying to figure out how much I should balance use of SO’s against Prefabs, for a final push to publishable quality of code and gameplay, in a quite modular game. One last refactoring…

You are the one who asked for what benefits ScriptableObjects bring, what replies were you expecting if not attempts at that? In my case, I don’t even use ScriptableObjects much now, if at all, but draw on what I’ve read and experienced to answer.

If you really want a visual comparison, create a monobehavior with some random variables, put it in a GameObject, and make it a prefab.
Create an instance of a ScriptableObject with the same variables as you have put in the monobehavior, and create an instance.
Go to your window explorer, and compare the filesize of the prefab and ScriptableObject instance.

Considering I’ve been using Unity for a decade or so now.

I have never heard anyone significantly praise SOs for their memory savings features. I may have heard it passingly mentioned that it could potentially be used for such.

But that is not the primary praise I see foisted upon SOs. The primary praise is the modularity of design it allows you to exercise on an asset level. Basically… as data containers (similar to how other assets like materials, animations, or pretty much all of this stuff:
7419869--907907--upload_2021-8-15_12-38-21.png

Before SOs, these were hard coded things from Unity.

Now I can create similar things like so:
7419869--907910--upload_2021-8-15_12-40-4.png
7419869--907913--upload_2021-8-15_12-44-46.png

Here’s one I especially like. Being able to modularize my build/input settings:
7419869--907919--upload_2021-8-15_12-48-7.png

That modularity in my opinion is the benefit of ScriptableObjects, and is the primary feature that I hear rung most often around the community since their release.

…

What I also do know is that the community has a butt ton of confusion around it as well.

And this confusion may even come in the form of talks/presentations that may either go over the heads of viewers. Or be put on by people who don’t know what they’re talking about. I can not speak to these specifically… for the same reason I can’t speak to the talks/presentations you mentioned already because you did not offer up any direct examples.

3 Likes

Why I and others have remained hyper focused on space savings is because of OP’s opening:

and inability to stray from it:

Even after being told that there is more to ScriptableObjects than that one thing:

And the point of my post that you’re quoting is to say…

what talks/presentations?

This topic of memory savings is a topic I rarely see. This thread being probably the only time I’ve actively engaged with the topic (noting not from a lack of engagement with Unity… noting my heavily engaged history with Unity).

I understand you and april may be “hyper focused” on this topic because of april’s OP. But that’s circular in nature. Of course this thread is about that topic, it’s what the thread was started for.

I am claiming I don’t believe the original statement nor this one:

(the statement I had quoted/responded to with that specific post you’re quoted)

Who is this “EVERYONE”?

I don’t see them.

The only people I see is OP. And they’re only saying they don’t believe the claims they heard these hypothetical others say.

OK…

Stop listening to these unknown actors then.

…

Basically. Why stay laser focused on a topic that OP clearly isn’t satisfied with the answer of. When their entire foundation for the topic is based on hearsay.

Try to understand that the materials you look at, as a seemingly god-like master of Scriptable Objects, and that which I come across as someone barely using them and wanting to learn more about them, are two entirely different groups of reading material.

I don’t understand the use case you’ve presented that you’re all chuffed about, at all. That’s how far apart we are.

So it would be bloody nice if you’d just take my word for it when I say I’m seeing almost ubiquitous claims of memory reduction in all I read and watch about why to use ScriptableObjects.

These things seem so simple and powerful that it boggles the mind how nobody has managed to trouble themselves to teach them in a manner suitable for those considering architecture of their games without examples. But that’s like a lot of programming, those with the knowledge forget what it’s like to not have the knowledge, insights and wisdom and instead distrust the stated experiences of others, and simply present their own experiences as though that’s normal and to be expected of everyone.

It’s one thing to distrust the claims of a person (water is wet) it’s entirely another to doubt the experiences of others (many have told me that water is wet).

And I get that you want mono/solo examples of something so you can repurpose their words and make it somehow my fault for misinterpreting what they’re saying “well… he’s saying this, and you should therefore think this…” but here’s the thing… every source I’ve read, every presentation I’ve seen attempting to justify using ScriptableObjects as the new god of Unity architectural considerations, they all say, at some point… memory reduction.

After a while, it got distracting, even though this wasn’t a factor in my considerations of whether or not to use ScriptableObjects (or how or why or when to use them, which are still things uncertain), AND I couldn’t see how it could be such a significant factor that EVERYONE I was seeing mentioned it as though it was a significant bullet point in the reasons to use it.

Hence the original question.

This isn’t a “god-like” thing.

This is a, you didn’t supply what you’re referencing.

Think of it like this. When someone comes onto the forums and is having trouble with a tutorial and they say “I was following this tutorial and they said do X,Y,Z, but I don’t get why.”

Our most often response is “What tutorial???”

Because yes… you may come across material I don’t. But that’s my point… We don’t know what material you’re talking about. We don’t know the quality. We don’t know what they’re saying in it. We don’t know if you misinterpreted/misrepresented what they said.

To say… “I heard a thing”, with out saying who, is called… hearsay.

I didn’t say “I heard a thing”, I said “I heard a thing A LOT”.

There’s a difference.

EDIT: ADD EVIDENCE FOR WHATEVER REASON::

NB: This is not how I searched for info about Scriptable Objects, it’s to prove to you that there might actually be a lot of talk about the memory reduction when using scriptable objects.

Of all the things to argue about, the experience of having read and heard this claim, many, many times, is probably the most asinine. Why bother with that? Why not just stick to "Here’s how much memory they can save… it’s not a lot… it is a lot… details… "?

Also…

Memory savings being a bullet point is different from:

Bullet points of reasons does not mean that each reason has equal praise. And it most certainly doesn’t mean “all hail”. Which is why I feel you may be misrepresenting the unsourced talks/presentations.

But who knows… maybe there are a couple people who blow the “memory savings” thing out of proportion.

I just doubt it.

It sounds like one of those things where people are saying:

“Scriptable Objects have many benefits including: a, b, c, d, e, f, g, h”

And one of them happens to be memory. Which it CAN assist in saving. It’s just not as significant as you assumed for whatever reason you assumed it since I don’t know what you saw/read/heard.

…

It’s still “I heard…”

I hear a lot of people say vaccines cause autism. Doesn’t mean it’s true!

In this metaphor, I came to a Doctor’s convention to ask if these lots of people had a point, and to what extent.

Why oh why are we going down this path?