Networked player names design pattern
I want to use player names to log scores.
I want each player to have a name that is set locally before joining any realtime session.
I want to store that name to player prefs.
when a player joins a session, I want their name to be shown in a textmeshpro line above their head.
What is a good model example for this?
2 Replies
Hi @Mikameel. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To implement networked player names with the design pattern you described using NormalVR (Normcore), we can create a custom RealtimeComponent to synchronize player names. Here's a high-level approach based on the information provided in the knowledge sources:
1. Create a custom RealtimeComponent for player names:
First, create a new script called
PlayerNameSync.cs
that inherits from RealtimeComponent. This component will be responsible for synchronizing the player's name across the network.
2. Create a corresponding model for the PlayerNameSync component:
Create a new script called PlayerNameSyncModel.cs
:
3. Add the PlayerNameSync component to your player avatar prefab:
Attach the PlayerNameSync component to your player avatar prefab and assign the TextMeshPro component for displaying the name above the player's head.
4. Set the player name before joining a session:
Before connecting to a room, you can set the player's name using PlayerPrefs:
5. Connect to the room:
Use the Realtime component to connect to a room as described in the Realtime documentation:
This approach follows the pattern described in the Synchronizing Custom Data documentation. It uses a custom RealtimeComponent to synchronize the player's name across the network, stores the name in PlayerPrefs for persistence, and displays it using a TextMeshPro component above the player's head.
Remember to add the PlayerNameSync component to your list of RealtimeComponents in the RealtimeView on your player avatar prefab.
This solution should provide a good starting point for implementing networked player names in your NormalVR (Normcore) project. You can expand on this to include additional functionality, such as updating scores associated with player names.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@365574199844274177> Kapa.ai is still learning and improving, please let me know how I did by reacting below.