Funkey
Funkey
NNormal
Created by Funkey on 7/29/2024 in #🤝ask-a-question
How to update a element in a realtimeArray for all clients?
@Normcore Assistant So it's acting like the data is syncing but the onChange doens't fire across all clients. It seems that the data is being synced based off behavior but I'm looping through the synced array to verify values onChange and logging them. The debugLog only fires on the client that changes the value and it doesn't account for everyone else's changed values.
19 replies
NNormal
Created by Funkey on 7/29/2024 in #🤝ask-a-question
How to update a element in a realtimeArray for all clients?
@Normcore Assistant The code I provided in the last example doesn't seem to work. I get an error when I attempt to index into the array.
19 replies
NNormal
Created by Funkey on 7/29/2024 in #🤝ask-a-question
How to update a element in a realtimeArray for all clients?
@Normcore Assistant
if (currentModel != null) {
// a model with no current data
if (currentModel.isFreshModel) {

// create players array
if (_players.Count <= 0) {
for (int i = 0; i < MAX_PLAYERS; i++) {
currentModel.players.Add(new PlayerModel());
currentModel.players[i].readyDidChange += ReadyDidChange;
}
}
}
if (currentModel != null) {
// a model with no current data
if (currentModel.isFreshModel) {

// create players array
if (_players.Count <= 0) {
for (int i = 0; i < MAX_PLAYERS; i++) {
currentModel.players.Add(new PlayerModel());
currentModel.players[i].readyDidChange += ReadyDidChange;
}
}
}
c# Would something like this work then? The model now has the realtimeArray called players and I'm subscribing to it's event on a fresh model like this.
private void ReadyDidChange(PlayerModel model, int value){
int index = 0;
int i;
for(i=0; i< 4; i++){
if(_players[i].Equals(model)){
Debug.Log($"Player {i+1} changed ready status to {value}");
index = i;
}
}
UpdateArrayReady(value, index);
}

private void UpdateArrayReady(int value, int index) {
// _players[0].ready = value;
_players[index].ready = value;
Debug.Log($"New array readies: [{_players[0].ready}, {_players[1].ready}, {_players[2].ready}, {_players[3].ready}]");
}
private void ReadyDidChange(PlayerModel model, int value){
int index = 0;
int i;
for(i=0; i< 4; i++){
if(_players[i].Equals(model)){
Debug.Log($"Player {i+1} changed ready status to {value}");
index = i;
}
}
UpdateArrayReady(value, index);
}

private void UpdateArrayReady(int value, int index) {
// _players[0].ready = value;
_players[index].ready = value;
Debug.Log($"New array readies: [{_players[0].ready}, {_players[1].ready}, {_players[2].ready}, {_players[3].ready}]");
}
c# Then above is how I'm handling the change.
19 replies
NNormal
Created by Funkey on 7/11/2024 in #🤝ask-a-question
Difference between avatar.ownerIDInHierarchy, avatar.ownerIDSelf, and avatar.realtime.clientID?
@Normcore Assistant For some reason, someone joining and leaving increases the player count. Like a two player game, and player 2 leaves and rejoins now makes that count 3 for some reason.
30 replies
NNormal
Created by Funkey on 7/11/2024 in #🤝ask-a-question
Difference between avatar.ownerIDInHierarchy, avatar.ownerIDSelf, and avatar.realtime.clientID?
@Normcore Assistant How does RealtimeAvaterManager.avatars.count work? Will it give me the proper headcount of players in the game or should I just loop through it and check the non null objects?
30 replies
NNormal
Created by Funkey on 7/11/2024 in #🤝ask-a-question
Difference between avatar.ownerIDInHierarchy, avatar.ownerIDSelf, and avatar.realtime.clientID?
@Normcore Assistant
for(i=0;i<6; i++){
Debug.Log(avatarManager.avatars[i]);
}
for(i=0;i<6; i++){
Debug.Log(avatarManager.avatars[i]);
}
C# This has a single client and I get an key not found error for i=1, which makes sense. I'm assuming that there is no null set to the avatars dictionary, it appears that a clientID will create a key value pair once someone joins. I'm assuming if someone leaves such as client 0 leaving, then the value will either be set to null or the key|value pair is removed from the avatars dictionary. Is that correct?
30 replies
NNormal
Created by Funkey on 7/11/2024 in #🤝ask-a-question
Difference between avatar.ownerIDInHierarchy, avatar.ownerIDSelf, and avatar.realtime.clientID?
@Normcore Assistant Sorry if this question seems trivial, but RealtimeAvatarManager.avatars[realtime.clientID] will be set to null if there is no avatar with the realtime.clientID that's used as the index into the avatars dictionary. Is that correct?
30 replies
NNormal
Created by Funkey on 7/11/2024 in #🤝ask-a-question
Difference between avatar.ownerIDInHierarchy, avatar.ownerIDSelf, and avatar.realtime.clientID?
Sounds good! Thank you for the help!
30 replies
NNormal
Created by Funkey on 7/11/2024 in #🤝ask-a-question
Difference between avatar.ownerIDInHierarchy, avatar.ownerIDSelf, and avatar.realtime.clientID?
@Normcore Assistant If I want a system that reassigns client ID's when someone leaves, should I just not use it? I notice that if a client leaves, the ID's don't get reassigned. E.g client 0 leaves and everyone ID's remains the sames. But if someone new joins, they get assigned to client 0 which isn't ideal for my logic.
30 replies
NNormal
Created by Funkey on 3/25/2024 in #💭feature-request
Clear a RealtimeArray
Just don't clear it off!
10 replies
NNormal
Created by Funkey on 3/25/2024 in #💭feature-request
Clear a RealtimeArray
Thank you! I've tried the workaround and I've found a strange bug where changes aren't synced on a fresh model until one of the client leaves. This is a very powerful and useful feature that I would love to see!
10 replies