Scriptable objects questions

So, I might just be incredibly dumb but please bare with me.

Essentially I was trying to do this project one way, then everyone told me my life would be a ton easier using scriptable object instead, and now I’m confused on if they actually work this way or not.

The jist of what I’m trying to do is I have a group of game objects, I make them scriptable objects within 1 group (to do, say, activate them and make them invisible). I need to be able to go through the list of objects at random times and activate one at a time so only one is active and goes invisible, while the rest stay inactive but visable.
I’ve gotten it to work with a single object, but I’m entirely stuck on how to scale it up.

So my question is basically, am I able to change 1 scriptable object at a time or does it force them all to change the same way? Everything I’ve read points to no, but with how many people told me to use them for this purpose makes me wonder if I’m just missing something.

Your question is just full of vagaries and confusion. It will be hard to help from this description:

What do you mean by “you make them ScriptableObjects”? GameObjects are GameObjects. They are not and cannot be ScriptableObjects, nor can they become ScriptableObjects.

Completely doable with a list of GameObjects. Not sure where the ScriptableObjects come into play here.

They are objects like any other. When you change one, it changes the one you changed, that’s it. Not sure how it’s relevant to the rest of the question though.

1 Like

I think I’ve been entirely misunderstood, but I’m not sure what other way to word it, my apologies. Worst part about self-teaching is you don’t know what things are normally called/correct terminology/anything like that aha.

I already explained I was trying to do this without scriptable objects, but I was constantly told that scriptable objects would make it all a lot easier, which is where my confusion comes into this. I have it all working with 1 object, using scriptable objects, but trying to scale it up is where I’m unsure on how it works.

I have 1 object, at a random time it’ll activate which will turn it invisible, and after an input from the user it’ll deactivate and turn visable again. I’m wanting to scale that up for multiple objects in the scene, but only 1 object activating at once. From what I’ve tested around scriptable objects, it’s hard/not possible to just activate 1 at a time, it instead activates all of them. This is why I asked if I’m just missing something/scripting them the wrong way. I hope that clears it up.

Totally agree… to combat this, slice your time between lots of different types of tutorials and learning resources.

DO NOT focus just on one thing but rather expose yourself to tons of different tutorials. Here’s a useful approach and minset: ask yourself, “Can I…”:

https://www.youtube.com/watch?v=b3DOnigmLBY

Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

How to do tutorials properly, two (2) simple steps to success:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!

If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

1 Like

A scriptable object is a single instance, which is one of its selling points. It’s a great way to share data with a bunch of different things, they are all accessing one thing.

Typically if you are using them for gameplay, you don’t modify that scriptableobject reference at runtime, because modifying them via code in playmode in the editor will modify them forever. Those changes will persist after you have stopped playmode, and closed the editor. They will not reset. To make things more confusing, when someone plays your game outside of the editor, changes made to the scriptable object via code don’t persist after they have closed the game. They actually do reset in that case.

So, in your case, you want to have many unique instances of a scriptableobject, so that you can modify them independently with code, and you don’t want to modify the original scriptableobject, with code, rather you just want to treat the original like it’s a prefab that you can instantiate gameobjects from, or a C# class that you can create instances of…

You can use ScriptableObject.CreateInstance to get unique temporary runtime instances of the scriptable object, and then you modify those. That’s what you’re looking for.

https://docs.unity3d.com/ScriptReference/ScriptableObject.CreateInstance.html

1 Like

Problem for me is I’m hard of hearing, this makes video tutorials very hard to follow as the vast majority have no subtitles, or automatic captions which add in it’s own issues. I’ve not ever really found a video tutorial I’m able to follow properly without a lot more effort than usual, so I’ve just stuck to text tutorials. Problem with those is those are almost always quite out of date, even for example the one I used for learning scriptable objects I had to go through and fix multiple bugs and errors that cropped up due to it being out of date which, while good as I can then more understand different things, that bug fixing is a lot more difficult while trying to learn brand new systems aha…

Ooh thank you! This helped a lot! I’ll have a mess around with the create instance and see how that all works!

1 Like