/// <summary>
/// The player who did the poking.
/// </summary>
VRCPlayerApi playerWhoPoked;
/// <summary>
/// The message to display when poked
/// </summary>
string previousPokeMessage = "Try To Poke Me!";
/// <summary>
/// The message to display when poked
/// </summary>
[UdonSynced] string pokeMessage = "Try To Poke Me!";
/// <summary>
/// Update the text when it changes
/// </summary>
void Update() {
if (parentHUDIsActive()) {
/// when the poked message is updated by the owner, change it for everyone.
if (previousPokeMessage != pokeMessage) {
debug($"previousPokeMessage {previousPokeMessage} is not longer equal to {pokeMessage}. Updating text.");
updateDisplayedText();
}
/// when the owner is changed to the player who poked, they can set themselves as the new poke message.
if (playerWhoPoked != null && Networking.IsOwner(playerWhoPoked, gameObject) && playerWhoPoked == Networking.LocalPlayer) {
debug($"Ownership of {name} given to {playerWhoPoked.displayName}. They can now try to update the poked text");
setPlayerWhoPokedMessage(playerWhoPoked);
playerWhoPoked = null;
} else if (playerWhoPoked != null) {
debug($"We have a player who poked {playerWhoPoked.displayName} set for {Networking.LocalPlayer.displayName} but it seems the owner of the object is still {Networking.GetOwner(gameObject).displayName}");
}
}
}
///// VRC FUNCTIONS
/// <summary>
/// On poke, display the player who poked this player in text
/// </summary>
public override void Interact() {
if (Networking.LocalPlayer != null && parentHUDIsActive()) {
VRCPlayerApi equipedPlayer = parentHUD.getEquippedPlayer();
if (equipedPlayer != null) {
debug($"{equipedPlayer.displayName} with poke hud has been poked by {Networking.LocalPlayer.displayName}!");
if (Networking.IsOwner(Networking.LocalPlayer, gameObject)) {
setPlayerWhoPokedMessage(Networking.LocalPlayer);
} else {
debug($"Ownership not posessed by to {Networking.LocalPlayer.displayName}, cannot update poked message yet. Getting ownership for poker.");
playerWhoPoked = Networking.LocalPlayer;
Networking.SetOwner(Networking.LocalPlayer, gameObject);
}
} else {
debugError($"Hud {parentHUD.gameObject.name} is active but has no equiped player!");
}
}
}
===================
I have this code. The debugger confirms that the player who owns the object is the local player before setting the sync'd variable pokeMessage.
However, pokeMessage never propogates until the second time I interact for some reason.
Is there something blocking the sync from occuring? Does checking the sync variable in update halt it's ability to sync between clients?
Since the player changing the variable is the owner, it should propagate, but it doesn't the first time. Please help. I have a test world as well for debugging.
LOGS:
===== first click:
MEEPLOG:: Ownership of Poke Collider given to MeepTest. They can now try to update the poked text
2020.05.20 14:03:20 Log - MEEPLOG:: MeepTest is trying to changing the sync'd HUD text. MeepTest is the current owner
2020.05.20 14:03:20 Log - [NetworkManager] OnOwnershipTransfered Poke Collider (UnityEngine.GameObject) from 2 to 2
2020.05.20 14:03:31 Log - MEEPLOG:: updating height to 0.9602525 for MeepTest from 1.162971
===== second click:
2020.05.20 14:06:36 Log - MEEPLOG:: PileOfMeeps with poke hud has been poked by MeepTest!
2020.05.20 14:06:36 Log - MEEPLOG:: MeepTest is trying to changing the sync'd HUD text. MeepTest is the current owner
2020.05.20 14:06:36 Log - MEEPLOG:: previousPokeMessage Try To Poke Me! is not longer equal to MeepTest poked PileOfMeeps. Updating text.
2020.05.20 14:06:36 Log - MEEPLOG:: hud text set to MeepTest poked PileOfMeeps