I have 4 GameObjects, a character controller script, an enemy manager script, and a damage system script that I would reuse for several different situations in the same way for each. Currently I put all those references into a static class that acts as a wrapper for those said variables but something like this is bad practice. At the same time, I don't want to resort to serializing a bunch of fields in the inspector for each of those situations. Would there be a better approach to this?
\$\begingroup\$ \$\endgroup\$
3 - 1\$\begingroup\$ What is your reason for reusing them? If reuse is needed to solve a specific problem, it would help to include that info. \$\endgroup\$Pikalek– Pikalek2022-06-03 16:51:51 +00:00Commented Jun 3, 2022 at 16:51
- \$\begingroup\$ @Pikalek I have a bunch of mini-game states where a set of game objects have to be revealed each time as well as have enemies set up and reinitialize a damage system. A player has a selection screen of mini-games and when one of the thumbnails is selected then we hop into that mini-game state and the events I mentioned in the first sentence happen. \$\endgroup\$complex problem– complex problem2022-06-03 17:08:03 +00:00Commented Jun 3, 2022 at 17:08
- 1\$\begingroup\$ What's wrong with serializing fields in the inspector? Can you provide more detail about what you're trying to accomplish and the approach you've already considered? \$\endgroup\$Kevin– Kevin2022-06-04 00:40:15 +00:00Commented Jun 4, 2022 at 0:40
Add a comment |
1 Answer
\$\begingroup\$ \$\endgroup\$
4 Scriptable objects are a good solution for storing sets of grouped data that need to be referenced in several spots. Note that scriptable objects are only really good for values that change during edit time. They are not well suited for values that change at runtime.
- \$\begingroup\$ ScriptableObjects can be used to store shared state/values that changes at runtime, as long as you recognize that the state/values will not be saved when you quit the game. \$\endgroup\$Kevin– Kevin2022-06-04 00:38:47 +00:00Commented Jun 4, 2022 at 0:38
- \$\begingroup\$ @Kevin the problem is that the runtime changes of scriptable object values are stored during editor play mode as if they are changed from the inspector. \$\endgroup\$Nikaas– Nikaas2022-06-04 09:48:47 +00:00Commented Jun 4, 2022 at 9:48
- \$\begingroup\$ @Nikaas If you're using the value only to store runtime state, just don't serialize it. \$\endgroup\$Kevin– Kevin2022-06-07 23:37:14 +00:00Commented Jun 7, 2022 at 23:37
- \$\begingroup\$ I prefer to make separate objects for runtime state \$\endgroup\$Adam B– Adam B2022-06-08 00:06:41 +00:00Commented Jun 8, 2022 at 0:06