Mulitplayer & Static Instances

Hi there,
I am just setting up the architecutre for what would be my first multiplayer game.

I am wondering, if I should avoid any static components as managers? For instance, player manager, handles the team of the local player. If player manager, is a static, instance, does this raise possible “cross contamination” with a non local player?

I am thinking no.
Yah?
:slight_smile:

Sorry, could you clarify what you mean by ‘static component’? I use several NetworkBehaviour classes manager that have a public static instance to themselves (i.e. singleton pattern) to break-up network logic into smaller, self-contained files and it seems to work well.

Any code snippets you have or are referencing would be useful for us to give you better feedback as well.

Best,
Arun

I mean, if I have a root manager, who all major funcitons run through (startGame(), endGame(), playerKilled(), playerScored() etc) (I do this so I have a single access point, if I need to notify many managers). If my root manager is public static instance, … I am thinking if I call it, rootMng.instance.doThis(), that will only be on a local level.

yes?

What do you mean by “that will only be on a local level?”

There is no problem with using classes with static instances (such as singleton classes) as networked managers.

For example, you could use a global singleton GameManager object which sends ClientRPCs from server to the clients to inform them on particular game state updates and such.

1 Like

Hi Guys,
What I am saying is if we can imagine 1 PvP, 1 player vs 1 player, over the network.

If player 1, collects coin, and as such tells the (defined as: public static Coin_Mng instance;) Coin_Mng.Instance.coinCollected(), there is no way this will fire acorss the network unless I instruct it to.

I am pretty sure I am right, just double checking.

You are right. You will always have to explicitly implement networking. There is nothing special with statics and networking whatsoever.

1 Like