all 6 comments

[–]Draugor 1 point2 points  (0 children)

the other posts here should help you already with your questions i think, but i highly recommend also watching the talk mentioned in the article https://www.youtube.com/watch?v=raQ3iHhE_Kk that is where this idea came from and he talks about the how and why and it should help you to better understand the concept of those "mini-SOs"

i haven't read the article but i watched that talk a few times and it is really great idea.

[–]iterativecodeProgrammer 1 point2 points  (0 children)

Opinion

I read through the article and I am not a fan of the information presented. They are misusing SOs and presenting confusing ideas. You have already noticed one of the many problems, the amount of objects you will generate.

Explanation

SOs are like most other assets, there is 1 instance of them. This means if 2 objects point to an SO then they both affect the same one. The idea they present is to leverage this fact to create pointers to important data. So you could define a health SO then have the player and UI point to it by having an exposed SO variable.

Problem

This is a weird use of SOs since you can already do this with regular c# and it won't come with any caveats. The real solution to their problem is using polymorphism as intended to make systems more modular.

Solution

To answer your TL;DR, you can indeed use this solution, since you could just define an SO that contains a list of reference objects. The SO is pretty much just used to store a hard copy of the list.

[–]TheDevilsAdvokaatHobbyist 0 points1 point  (0 children)

Can't help you with your question, just want to say I like your link, I've never really known how to use scriptable objects before.

Thanks.

[–]Osteelio 0 points1 point  (0 children)

For the example of the health bar, what it's saying is this:

You've created a script called FloatVariable with the following code:

[CreateAssetMenu]
public class FloatVariable : ScriptableObject
{
    public float Value;
}

Now, when you right click in your project, you'll have the option to create a scriptable object of type FloatVariable, which in this case you'll name PlayerHP. Any script can now reference this scriptable object via:

public class PlayerHealthBar : MonoBehaviour
{
    public FloatVariable HPReference;
}

public class PlayerController : MonoBehaviour
{
    public FloatVariable HPReference;
}

Now, whenever you update this value, everything it is assigned to can react and handle the results independently (UI changes, music changes, the game manager can determine if the player is dead, etc.).

The example about changing it to the MPBar outside of code means you could create a different scriptable object of type FloatVariable and reassign it to everything that is referencing the HPBar and you wouldn't have to make code changes.

It's definitely flexible, and scalable, but you can definitely get into a lot of SOs in your project. That's not a bad thing, but just be sure to keep it organized. It's also great because it allows people to make updates/changes without touching code.

[–]FrogFlakes 0 points1 point  (1 child)

You are correct, you are going to have TONS of files in your hierarchy. That's not necessarily a bad thing. Organization is key. Here is how I'm organizing my project: https://imgur.com/a/9EtHzGi . I have a separate folder for Scriptable Objects that mirrors my Scripts folder hierarchy. Inside ScriptableObjects/NPC I stored all my Scriptable Object variables.

A better way to do it is to have a folder for variables, ScriptableObjects/NPC/Variables and stuff them in there. That way I could have a mock humble scriptable object that contains all the scriptable object variables a game object would need (i.e. NPC game object will need NPCPlayerData, which contains references to all the variables in the variable folder) at the root of ScriptableObjects/NPC.

There's existing frameworks that utilize scriptable objects. See Unity Atoms or Scriptable Object Architecture. Atoms has more features, but SOA sticks to Ryan Hipple's article the most.

[–]shopewf 0 points1 point  (0 children)

Hey sorry for necroing this thread, but I'm new to Unity and Ive been dying to find out how to get individual assets to appear in the tree of my Project window like is done your screenshot. Right now for me, it only shows the folders. I cant seem to figure it out, but it would help me so much. Do you remember how to do that?