1
\$\begingroup\$

I am a former Unity user, and after a big pause in game dev decided to try out Monogame (I'm a software engineer IRL so I'd figure this is the best way to go).

In Unity I was using scriptable objects to decouple my data from their mutators / consumers, as explained here.

For example, I would have a scriptable object that represented my player's health, and my player entity would just have it as a public field and in the editor I could drag the scriptable object in.

My UI was also interested in the health, so I could just expose a public field on my health bar and it would consume it.

Hence my data was decoupled from the once using it and no dependencies where between different systems.

So I'd like to reproduce this in Monogame.

I was thinking of using something like a service provider / locator pattern where I could register the health for my player for example and each system needing it would retrieve it trough that.

This seems less flexible though then the way Unity shows it, as I could have multiple 'healths' registered, and to get the right one would mean I'd have to find a way to retrieve the right one (which is totally possible but more complex then just dragging in the right scriptable object in Unity).

Someone found a nice way of doing this before I dive in?

\$\endgroup\$
4
  • \$\begingroup\$ What's so complex about 1 function call with 2 parameters? \$\endgroup\$ Commented Jun 27, 2021 at 11:25
  • \$\begingroup\$ @Shadows In Rain what do you mean, giving a second parameter to the service provider, this would mean I would've to keep constants for those 2nd parameters, not being complex indeed, but relative to how it worked in unity it would be more. \$\endgroup\$
    – TanguyB
    Commented Jun 27, 2021 at 11:47
  • 1
    \$\begingroup\$ You are comparing apples to oranges: a powerful UI with support for de/serialization and drag-and-drop on one hand, and pure code on the other hand. Of course you have to pass the key that identifies the right player, the UI did that for you implicitly. Anyways, mainstream DI/SL frameworks should support keying out of the box, and if not, implementing that is almost trivial. \$\endgroup\$ Commented Jun 27, 2021 at 12:05
  • \$\begingroup\$ Ok thanks for the answer, as I would've thought then ( I was hoping for some data oriented manner of doing I'm missing, coming from the OOP world 8h a day, thinking in a data oriented manner can sometimes quirk me. Thx anyways \$\endgroup\$
    – TanguyB
    Commented Jun 27, 2021 at 12:33

1 Answer 1

0
\$\begingroup\$

In MonoGame you are welcome to implement any structure you want.

Remember the KISS principle. Don't over think it or over engineer.

A single static class can hold any/all game wide data.

A public static int Score = 0, Health = 100; in Game1.cs is sufficient for most purposes.

Multiple health's is achieved via instance health variables in each class.

\$\endgroup\$

You must log in to answer this question.

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