I am currently working on an intricate digest system for a sort of Tamagotchi-esk pet simulation game, mostly as a pet project (excuse the pun), and I was eager to implement ScriptableObjects in it. However, I found that there were a few major issues that may end up costing me in development time down the road.
What I am trying to do:
- Create a stomach system that holds various nutrients and processes them on regular interval.
- Have a monster with various vitals such as health and energy that are effected by the digestive process.
- Have different species that process said nutrients slightly, or perhaps even dramatically different from one another (herbivores versus carnivores and the like).
What I Started Doing:
- I wanted to create my monsters using a composition pattern, such as TonyTi talks about in this thread: RPG Inventory
- I setup a Monster (ScriptableObject) that holds a list of MonsterAttribute(s) (abstract ScriptableObject), and then a subclass of MonsterAttribute called Stomach, which holds a list of Nutrients.
- It’s a bit complicating and I imagine it will only get more complicating down the line, which is why composition and modularity are very important for this project.
The Trouble:
- I’m ok with creating assets of these ScriptableObjects and composing a monster outside the scene, but my issue is that these monsters will be mutable within the game, and I didn’t want them touching the base template, only copying from it. Do I need create a set of separate classes to transfer the data to, or can I instantiate these ScriptableObjects and use them separate of the template in the scene?
- Also, I would like to be able to tweak these values after I have the instantiated, mutable monster created in my scene, but I don’t quite understand how I would get at those properties.
- I like the idea of composition, but I don’t like the idea of having so many separate little pieces that are unique to each monster’s base template. Perhaps in practice these pieces will be more reuseable, but it’s very hard to predict at this time. Maybe your insight will help relieve my anxiety around using this ScriptableObject pattern.
Lastly, I know everyone keeps saying that ScriptableObjects are completely serializeable, but it still feels like you need a firm foundation of how to make good editor scripts in order to get them to show up as expected (if I have a list of ScriptableObjects, each one doesn’t expose their public properties by default, they show up like another list of objects.) Is my understanding of serialization inaccurate?
Thanks for any insights!
Can I get a reply just to show that my thread is appearing properly?
-
the component/monobehaviour design in unity follows a composite pattern. They are inherent composite.
-
ScriptableObject doesn’t inherently follow the composite pattern (though you can adapt them to)
I honestly don’t know why you’re using ScriptableObject for this. Why not use MonoBehaviour’s attached to GameObjects in scene? That way they’re mutable in scene!
Create a Prefab of the GameObject as well. Nice thing then is when you put it in the scene, a copy is made, and when you modify it in scene it doesn’t effect the prefab!
I really appreciate the reply lordofduct, I was worried I had setup my post incorrectly.
ScriptableObjects felt more persistent than MonoBehavior objects, and I liked a lot of the modularity they offered. Perhaps I am trying to fit a square peg in a round hole. I suppose it does make more sense to do this with MonoBehavior. I’m not sure excited about using prefabs as they can get bloated and difficult to manage in large projects, but perhaps I need more practice with them.
My project is likely to get enormous even if I keep it relatively unambitious, so I’m being very careful about he base framework. I need something very flexible (which is why I’m more interested in compositional design). I’ll give the prefabs a try and see what I get.
Thanks again for the feedback!
The trick is that, at some point I would like to pass a “Food” item to the Monster to eat. I would like this food item to be composition of elements including its nutritional values, what features it has (is it fuzzy, red, squishy), and whether it has any special effects (poisonous, triggers outside event, mutates monster). I do not yet have an exhaustive list, which is why I like the idea of composing the objects of many different parts before passing them. But this is something that doesn’t feel like it would live in the scene, at least, it’s data doesn’t need to be instantiated. So, I feel more inclined to use a ScriptableObject, but I’m not sure how to setup that ScriptableObject to where I can easily check which things its composed of.
Have any of you heard of systems or design patterns appropriate for what I’m trying to do?
If “Food” doesn’t live in the scene. Then use a ScriptableObject for that.
There’s nothing saying you can’t combine components and ScriptableObject.
But from your original post, this stomach sounds like it’s part of the ‘pet’ which IS in the scene. So maybe you then use a Component for that then.
I don’t know though… I don’t know your design, you don’t seem to know where your design is going either, you seem to be doing a lot of pre-planning with the expectation that this system will grow, but you’re not there yet. So you’re glomming onto this concept of “composition pattern” hoping it’ll allow you to grow as time passes.
Personally I’d start diving in now and refactor as things grow. Stop over complicating it up front before you’ve even gotten that far.
But eh… that’s just me. Do what you need. I have no idea really… again, I’m not you, I don’t know what you really want to do.
I’ve been diving into the project for a while now. I’ll get pretty far then hit a major road bump. That bump tends to be an issue with the fundamental system not being expandable enough. I’ve spent countless hours on the project only to come to the conclusion that I need to start over from the beginning again. The biggest thing I want to avoid are massive conidtional branched setup through if-statements or switch-statements, plus I’m trying to practice better coding techniques and patterns. This is all still in the researching and prototyping phase, so things are going to be inevitably wishy-washy, and I do apologize for that.
The biggest issue I’m experiencing right now is that I will starting building a system using methods I just learned, and then halfway in, I’ll realize I have no idea how to implement the system once it’s done. So, I go back and reiterate until I have something is expandable and that I know how to properly use.
Thanks again for all the help, I guess I need to work more on this myself until I have something less vague to present.