PunTeams? Custom properties? Managing multiple prefabs?
Options
Hey, not sure exactly where to start so I'll try to keep it organized. I heard programmers like that kinda thing, ya? ;P
First, just a quick explanation of what the game involves in relation to this situation:
-Simple 2D game, single scene, single camera
-Two teams of 5
-Each team will start with one ''elite'' and 4 ''lessers''
-The 4 lessers on each team will be able to upgrade into a third character type (lets just call it ''warrior'') in game, and upon death, respawn as a lesser again.
Each of these classes has a separate look, movement, and abilities (obviously?).
What I'm trying to do/need:
In short, I'm trying to create a team selection / character selection / ready up menu. Once everyone in the room has picked a team, a class/character, and clicked "Ready", the masterclient (or anyone or even just an auto countdown) can start the game, and finally everyone gets instantiated with the correct class and on the correct team.
I swear the more I read/study the less I'm understanding. I've resorted to this post as a way to step back and wipe the slate clean if you will and start over with a fresh foundation. I know the menu thing has come up (alot) but either I'm missing something or the specifics aren't quite what I need...
Am I even approaching this correctly??
I can't seem to find anyone that talks about the "correct" way, or a standard/common practice way (or even just A WAY really) to handle this kind of - what should be basic - system of players choosing different characters. All the tutorials and reference material seems to focus on instantiating the same prefab for all players.
My thoughts on how to accomplish this have been:
A. Upon entering room, instantiate an "invisible" player prefab containing only scripts involved with communications to the network and then instantiating and childing the elite / worker prefab to their respective owners after selecting.
B. Create a prefab that has all the different classes movement scripts, sprites[], ect and activate/deactivate the components as needed.
C. Don't bother with an "invisible" player prefab. Since the client is connected, save their team and character selection with PunTeams and custom properties respectively. Then instantiate the specific character/team they've chosen. On start of a new game wipe the custom properties and allow players to reselect their roles (or change teams if necessary).
Some questions:
What is the standard convention of handling something like this?
What exactly "are you" as a connected client before any instantiation?
Where should the script be that handles all this selection? (a gamemanager script in the scene for everyone, or a script on each player/client?)
There are more questions but I think if I can just get over this instantiating selected prefab they will answer themselves. Plus, this post has already become a short novel so I'll end it here...
If you're still reading this thanks a lot! If you didn't want to read that wall of text but still want to help:
TLDR: How do i instantiate different prefabs for different players, while also limiting the max/min number of each class..keeping in mind that these will later be killed and respawned as potentially different prefabs.
First, just a quick explanation of what the game involves in relation to this situation:
-Simple 2D game, single scene, single camera
-Two teams of 5
-Each team will start with one ''elite'' and 4 ''lessers''
-The 4 lessers on each team will be able to upgrade into a third character type (lets just call it ''warrior'') in game, and upon death, respawn as a lesser again.
Each of these classes has a separate look, movement, and abilities (obviously?).
What I'm trying to do/need:
In short, I'm trying to create a team selection / character selection / ready up menu. Once everyone in the room has picked a team, a class/character, and clicked "Ready", the masterclient (or anyone or even just an auto countdown) can start the game, and finally everyone gets instantiated with the correct class and on the correct team.
I swear the more I read/study the less I'm understanding. I've resorted to this post as a way to step back and wipe the slate clean if you will and start over with a fresh foundation. I know the menu thing has come up (alot) but either I'm missing something or the specifics aren't quite what I need...
Am I even approaching this correctly??
I can't seem to find anyone that talks about the "correct" way, or a standard/common practice way (or even just A WAY really) to handle this kind of - what should be basic - system of players choosing different characters. All the tutorials and reference material seems to focus on instantiating the same prefab for all players.
My thoughts on how to accomplish this have been:
A. Upon entering room, instantiate an "invisible" player prefab containing only scripts involved with communications to the network and then instantiating and childing the elite / worker prefab to their respective owners after selecting.
B. Create a prefab that has all the different classes movement scripts, sprites[], ect and activate/deactivate the components as needed.
C. Don't bother with an "invisible" player prefab. Since the client is connected, save their team and character selection with PunTeams and custom properties respectively. Then instantiate the specific character/team they've chosen. On start of a new game wipe the custom properties and allow players to reselect their roles (or change teams if necessary).
Some questions:
What is the standard convention of handling something like this?
What exactly "are you" as a connected client before any instantiation?
Where should the script be that handles all this selection? (a gamemanager script in the scene for everyone, or a script on each player/client?)
There are more questions but I think if I can just get over this instantiating selected prefab they will answer themselves. Plus, this post has already become a short novel so I'll end it here...
If you're still reading this thanks a lot! If you didn't want to read that wall of text but still want to help:
TLDR: How do i instantiate different prefabs for different players, while also limiting the max/min number of each class..keeping in mind that these will later be killed and respawned as potentially different prefabs.
0
Best Answer
-
Hi @fractylan,
good to hear you found a partial solution to your problem. Maybe I can help with some additional input. But firstly some of your questions from your thread opening.What is the standard convention of handling something like this?
I guess there isn't a standard convention or any kind solution that works perfectly for every game.What exactly "are you" as a connected client before any instantiation?
Well, you are a connected client in this stage, everyone else knows that you are 'there'.Where should the script be that handles all this selection?
Again there is no general solution and this is related to what you implement, what your hierarchy looks like and so on. But maybe I can give some more input you might want to think about.
So first of all: I guess you don't need to instantiate any networked object in this stage. When selecting a character you can write the selected character (either name, unique ID or similar) to the Custom Player Properties (I currently don't know if you already do this, you just wrote about Custom Properties - Room has Custom Properties, too). The Custom Player Properties are automatically synchronized across the network so they get also updated on other clients as well. When receiving the update,OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps)
will be called. Using this callback and the provided data each client can update their local view with the received data. For example if the character has chosen the 'elite' the character's placeholder on the GUI can be updated with a picture of the 'elite'. You will still have to find a solution how to bind a PhotonPlayer to a certain placeholder on the GUI.
To check if a client is ready, you can use a toggle on the GUI and also write the result to the Custom Player Properties. Then you have two options on the MasterClient. You can either check regularly if all clients are ready or you can increase (and decrease) a background counter and check if it reached the amount of players (10 in your case). Make sure to also listen forOnPhotonPlayerDisconnected(PhotonPlayer otherPlayer)
to properly decrease the counter if necessary.
To start the game you can either load a new scene by using PhotonNetwork.LoadLevel or disable the GUI overlay you used for character selection. In both cases you can use a RiaseEvent call afterwards, to tell all clients to instantiate their chosen characters by using PhotonNetwork.Instantiate.
Hope that helps you finding a properly working solution for your game. If you have further questions, please feel free to ask.5
Answers
-
Writing all that down seemed to help alot. I ended up figuring out how to instantiate a selected character type (lol, just setting that string... overthinking it much?)
I'm still having some trouble with custom properties tho. Will look around on the forums, i'm sure its been answered.0 -
Hi @fractylan,
good to hear you found a partial solution to your problem. Maybe I can help with some additional input. But firstly some of your questions from your thread opening.What is the standard convention of handling something like this?
I guess there isn't a standard convention or any kind solution that works perfectly for every game.What exactly "are you" as a connected client before any instantiation?
Well, you are a connected client in this stage, everyone else knows that you are 'there'.Where should the script be that handles all this selection?
Again there is no general solution and this is related to what you implement, what your hierarchy looks like and so on. But maybe I can give some more input you might want to think about.
So first of all: I guess you don't need to instantiate any networked object in this stage. When selecting a character you can write the selected character (either name, unique ID or similar) to the Custom Player Properties (I currently don't know if you already do this, you just wrote about Custom Properties - Room has Custom Properties, too). The Custom Player Properties are automatically synchronized across the network so they get also updated on other clients as well. When receiving the update,OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps)
will be called. Using this callback and the provided data each client can update their local view with the received data. For example if the character has chosen the 'elite' the character's placeholder on the GUI can be updated with a picture of the 'elite'. You will still have to find a solution how to bind a PhotonPlayer to a certain placeholder on the GUI.
To check if a client is ready, you can use a toggle on the GUI and also write the result to the Custom Player Properties. Then you have two options on the MasterClient. You can either check regularly if all clients are ready or you can increase (and decrease) a background counter and check if it reached the amount of players (10 in your case). Make sure to also listen forOnPhotonPlayerDisconnected(PhotonPlayer otherPlayer)
to properly decrease the counter if necessary.
To start the game you can either load a new scene by using PhotonNetwork.LoadLevel or disable the GUI overlay you used for character selection. In both cases you can use a RiaseEvent call afterwards, to tell all clients to instantiate their chosen characters by using PhotonNetwork.Instantiate.
Hope that helps you finding a properly working solution for your game. If you have further questions, please feel free to ask.5 -
thanks so much for the reply!! - using the OnPhotonPlayersPropertiesChanged() method and some RPCs I was able to cut my code in half while at the same time fixing all the issues I was having AND making the code more robust and easily manipulatable.0