Getting global ID of other player
I'm trying to broadcast a message via RealtimeModelEvent from one player to another. In the event handler, I only want the event handler of the receiving player to act on it. To do this, I'd like the event to include some kind of recipient ID, so that all clients who receive the evnet can check the recipient ID against their own ID. Is there some kind of ID I can use for this purpose which is consistent within a given room?
2 Replies
Hi @kyle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, you can use the client ID for this purpose, which is consistent within a given room in Normcore.
When working with Normcore's RealtimeModel events, you can include the sender's client ID in your event data and have recipients check if they are the intended target. The client ID is a unique identifier assigned to each client in a room.
Here's how you can implement this:
1. In your RealtimeModel, include properties for both the sender ID and recipient ID:
2. When sending a message, you can get your local client ID from the Realtime instance:
3. When receiving a message, check if you're the intended recipient:
You can get information about who is in the room using RealtimeAvatarManager's
avatars
dictionary, which maps client IDs to their respective RealtimeAvatar components RealtimeAvatarManager.
This approach ensures that while all clients receive the event (as Normcore broadcasts model changes to everyone), only the intended recipient will act on it.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@401595391549898754> Kapa.ai is still learning and improving, please let me know how I did by reacting below.