Display Other Player's Attributes in UI

jmarsh411

New member
I'm working on a PUN 4 player party game where I want to show each player's score at the bottom of the screen.

I created an attribute called Score and added the means to increase it. Then I tested using Debug.Log and I could see each client's score updates in the logs. I have this hooked up to the UI with a script called AttributeTextMonitor, which is basically a copy of AttributeMonitor except using Text instead of a Slider. The UI updates the local player's score just fine.

My attempt to associate a different character with a different UI Score was to add a script that assigns the character's GameObject to the CharacterMonitor's Character property.
C#:
public class UIAttacher : MonoBehaviour
{
    private PhotonView photonView;

    void Start()
    {
        photonView = GetComponent<PhotonView>();

        GameObject PlayerUIRect = GameObject.Find(string.Format("P{0}Rect", photonView.ControllerActorNr));
        foreach (AttributeTextMonitor attributeTextMonitor in PlayerUIRect.GetComponentsInChildren<AttributeTextMonitor>())
        {
            attributeTextMonitor.Character = gameObject;
        }
    }
}
The script does hit my breakpoint in AttributeTextMonitor's OnAttachCharacter method and it looks like it's assigning properly. But the UI's score remains tied to the local client's score. I've been trying different things with no luck.

I realize this isn't what attributes were designed for, but once I saw and tested that they do synchronize I was curious about how flexible they could be. A more natural application would be a co-op game where you want to see your partner's HP in your UI.

So a couple questions:
1. Does Attribute system support showing other player's attributes in the UI?
2. How is CharacterMonitor's Character property intended to be manipulated?
 
1. Does Attribute system support showing other player's attributes in the UI?
No - it doesn't. The attributes are not synchronized across the network so you'll need to add support for that. I would synchronize it with the serialization method similar to how the PunTransformMonitor is synced.

2. How is CharacterMonitor's Character property intended to be manipulated?
Your steps above are correct. The problem is that the attributes are not synchronized across the network.
 
I was able to get the behavior I was looking for by modifying a line of the AttributeMonitor. If I need something more complex later, I'll look at the PunTransformMonitor.

Thank you!
 
I was able to get the behavior I was looking for by modifying a line of the AttributeMonitor. If I need something more complex later, I'll look at the PunTransformMonitor.

Thank you!
Hi can I ask how did you synch the attribute?
 
Hi can I ask how did you synch the attribute?
I didn't. So if a player were to join midgame (not an option in my game) or a if player lost connection and rejoined, their score would be out of sync. It just looked synced because all clients would update their copy of the attribute using the same logic.
 
Top