0
\$\begingroup\$

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?

\$\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
    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\$ 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
    Jun 4, 2022 at 0:40

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\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
    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
    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
    Jun 7, 2022 at 23:37
  • \$\begingroup\$ I prefer to make separate objects for runtime state \$\endgroup\$
    – Adam B
    Jun 8, 2022 at 0:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .