SCRIPTABLE OBJECTS in Unity

Brackeys · 1.1M views · 2018 · 8:57

Open on YouTube

Game programming & enginesIndie game developmentSoftware architecture & designtutorial

Why Stack Overflow recommends it

Stack Overflow users link it when answering Unity questions about storing items, cards or configuration data outside MonoBehaviours.

Recommended by 8 people across 8 different months, 2019 to 2022.

What it is

A short Brackeys tutorial introducing Unity's ScriptableObjects as a way to store game data as editable assets. It walks through a worked example of building Hearthstone-style cards, including a ScriptableObject class and a component that displays the card data.

What people said

Recommends user11241144 · 2019-03 · Stack Overflow · on “Unity3d - Color different parts of a sprite/image separately”

You will have to save every part separately. As I understand you will have more than one image to color. If so, I would suggest you to use scriptable objects to store images which are made of these separated sprites. Here's a video talking about basics of scriptable objects and how to use it. [this video] This is some basic code, how I imagine it would look for you to save the image: [CreateAssetMenu(fileName = "Sprite Scriptable Object", menuName = "Sprite SO")] public class ScriptObje : ScriptableObject { public string naming; public List<Sprite> parts; }

Recommends Ali Kanat · 2019-04 · Stack Overflow · on “Unity Dota style loading screen”

I think this is a perfect case to use for Scriptable Objects [LINK] in Unity. Because as far as i remember there are around 100 heroes in Dota 2 and only 10 of them will be picked. So the images in this loading screen would change based on player input. Therefore, you should create scriptable objects. Then you can change the image(hero) also modify/add nick names to it in Run time. So to sum up you will have 10(in Dota but 6 is your case) scriptable object in your scene but you will only modify the images and nicknames after player selects the heroes. Another benefit would be since they are objects you can easily animate them move up and down adjust however you want. Here is a tutorial [VIDE

Recommends Daruden · 2019-05 · Stack Overflow · on “How I call the ShootingSettings method from the Update only when there are changes?”

I personally suggest you check ScriptableObjects, it`s a good thing to learn. Here are some videos that could help you. Brackeys: [this video] Unite Austin 2017 - Game Architecture with Scriptable Objects: [LINK]

Recommends Jee · 2020-05 · Stack Overflow · on “C# Make a class return its instance without a function or variable”

Three options to do what you are looking to do: Make a static property/field with the static keyword in the PublicThings class Make a ScriptableObject [LINK] and attach it to the item that is calling it ( video tutorial [this video] ) Utilize the Singleton Pattern [LINK] (I would suggest avoid using this method before trying the other two) Also it's worth noting that the Singleton Pattern doesn't necessarily solve your problem. You will still have to call something like PublicThings.instance.Score . Hope this helps.

Recommends Ahmet Dara VEFA · 2020-08 · Stack Overflow · on “Unity 3D: Should I make an extensive script or multiple smaller ones for in game items?”

you can easily create multiple versions(or instances) of a scriptable object in editor instead of using prefabs or some other method. Moreover they provide a nice formatted environment to set your values. Check this [this video] video from brackeys for more details.

Recommends Bawenang Rukmoko Pardian Putra · 2020-09 · Stack Overflow · on “Good practices for storing readonly data in Unity”

Why don't you just use ScriptableObject ? It's the default way for Unity to store data in the game. You can also edit it from the Unity Editor instead of using another external editor. You can also drag-and-drop any resource from the game project's folder into it (eg. the texture of the head, the whole localized sting as data, the dialog audio clips, etc) [LINK] [this video]

Recommends verified_tinker · 2020-10 · Stack Overflow · on “How to Deal Cards to 4 players in Unity?”

Cards are a prime candidate for Scriptable Objects — a Unity-specific, designer-friendly method of creating new cards, instead of using code-based databases. Brackeys has an excellent tutorial [this video] on this exact use case, so I won't waste time on that here. Once you've created the class deriving from ScriptableObject and created assets based on that, and you've created a MonoBehaviour class (component) for reading and displaying that data (the tutorial covers this also, as CardDisplay.cs ), you need to save the Game Object with that component as a prefab [LINK] . Finally, you'll create another script that references the prefab and instantiates it 4 times. For example: // You'll drag the p

Recommends ieskela · 2022-12 · Stack Overflow · on “how do i get the values stored inside a gameobject from a script?”

In Unity, the GetComponent<> method can only fetch a class deriving from the MonoBehaviour or Component class. In this case, the item class does not derive from MonoBehaviour , instead, it derives from ScriptableObject . How to fix There are two ways that would work to fix this problem. The first way that you can fix this is by changing the class in which the item class derives from to MonoBehaviour , instead of ScriptableObject . The second, more complicated way to fix this problem is to create a variable to hold the ScriptableObject , instead of fetching it with GetComponent<> . The code would look something like this: ... public item item; void Start() { Debug.Log(item.Slot); } ... You sh

Cites Iggy · 2019-08 · Stack Overflow · on “Upgrading the Character”

You should distinguish between configuration data , and logic data . Configuration data does not change. e.g. Weapon magazine size. Logic data does change. e.g. Bullets in the magazine. Logic data is unique and only exists within some object instance, while configuration data exists in a database and is identifying by an id . The following is just an example code that demonstrates the idea. Data: public class WeaponData { public string id; public float spread; public string projectileId; } public class ProjectileData { public string id; public int damage; public string prefabPath; } Library: public static class Library { public static Dictionary<string, WeaponData> Weapons; public static Dic

Cites Afridi Kayal · 2021-06 · Stack Overflow · on “Set a variable within a Unity class”

The error in your code is that you have written these: // splits up the text file into the list of lines textLines = textFile.text.Split('\n'); // iterates over the course of the list of lines, splitting up the names and dialogue, then sorting each into its respective list for (int i = 0; i <= textLines.Length - 1; i++) { names.Add(textLines[i].Split(';')[0]); dialogue.Add(textLines[i].Split(';')[1]); } Inside the class instead of a method inside the class. Coming to the actual problem, I think you should use a ScriptableObject in this case. They provide an Awake (Similar to Awake in MonoBehavior) method in which you can write the above code so that it gets executed when the game starts. [Cr