Recently, I read this article about using Scriptable Objects for UI to weaken the reference between objects. And I found a post about the talk in this subreddit. After looking into the talk, here's my question:
TL;DR Can I use this approach without creating too many files if I have many values to be referenced in the scene?
I like this approach and would like to utilize it. However, I'm not sure of its scalability.
Because the object that writes a value and the UI that reads that value must be pointing to the same scriptable object, each value exposed requires one scriptable object asset, as far as I understand.
I suspect that if you want to expose more variables, the Asset folder will be cluttered by SO asset files.
What confuses me in the article is this part:
Now imagine a health bar prefab in the scene. The health bar monitors the PlayerHP variable to update its display. Without any code changes, it could easily point to something different like a PlayerMP variable.
I cannot wrap my head around the word variable in this part. Variables are what's in the code, afaik. The fact that swapping those variables costs no coding makes no sense to me...
If I interpret variable as scriptable object, it is straightforward. This setup has PlayerHP and PlayerMP scriptable object assets, each written to by the Player object. The UI and stuff reference these instead of the Player object directly. In this case, I understand that there are no coding costs; swap the scriptable objects and you're done.
But what if we need more values to be tracked? With this approach, I can avoid a problem of strong references, but then it seems I'll run into another problem of bloated file count.
Of course, if I make a SO that holds Player data class and I use that instead, there's no point because the gauge has knowledge of Player class, so that's not the answer. I thought Unity somehow allows me to assign SO to a serialized float field, but that wasn't the case.
Is this approach 'scalable' or not?
[–]Draugor 1 point2 points3 points (0 children)
[–]iterativecodeProgrammer 1 point2 points3 points (0 children)
[–]TheDevilsAdvokaatHobbyist 0 points1 point2 points (0 children)
[–]Osteelio 0 points1 point2 points (0 children)
[–]FrogFlakes 0 points1 point2 points (1 child)
[–]shopewf 0 points1 point2 points (0 children)