Enable Unity's Ui only for the player how triggered it

Options
Hello.

I am having quite a hard time trying to find a solution to my problem.
I am trying to activate a panel with Unity's new UI, but this panel to be active only on the screen of the player who triggered it and not to the others. I am trying to use photonView.isMine but it is not behaving as it should. the problem for this is that if I trigger the panel on a view that is not mine, it shows the panel only on my view, so this is not what I need. I need the panel to be shown only on the screen of the player who triggered it.
Your help would be much appreciated.
Thanks!

Comments

  • Tobias
    Options
    If you only need to show it on the player who triggered it, why use network synchronization at all for that?
    You can simply use it like any local UI.
  • teoteo
    Options
    Thank you for your answer. The thing is that if I activate/instantiate a gameobject using SetActive/Instantiate this action is automatically visible in all instances of the game. I'm not syncronising anything with PhotonView - but the gameobject is visible for all players. I spent hours to find a solution for this. Would a code snippet from my project be useful?
  • teoteo
    Options
    I use network synchronozation in my game for the chat system and I also synchronize many of the actions inside the game, but some UI Panels I preffer them to b visible only local, for the player who triggered it. Is it possible to achieve this using Photon and can you please point me in the right direction of doing this?

    Thanks
  • vadim
    Options
    Hi,
    Remove PhotonView component from UI panel. This will break synchronization and make panels appearance independent on all clients.
  • teoteo
    Options
    Hi,
    I have tried this, first thing, activating an UI Panel without any PhotonView Component.
    I even tried activating locally a cube, again without any PhotonView Component.
    In both cases, it is not behaving as expected, both gameobjects are activated on all Player Views, even if they do not have a PhotonView component on them. :(
    So, I really do not what to do next ..
  • vadim
    Options
    Would be interesting to look at simple repro app where cubes synchronized w/o PhotonView's.
    How do you "activate" cubes, by the way?
  • teoteo
    Options
    I activate them as I would without any PhotonView component.
    Hitting a collider, OnTriggerEnter(Collier col) and then cube.setActive(true).
  • teoteo
    Options
    Hi,

    No one can point in the proper direction of solving my issue?
    Thanks
  • teoteo
    Options
    Hi,

    So I've found what is causing the first appearance of a panel for all players, when triggered.
    The player prefab, which I instantiate OnJoinedRoom and which triggers the panel has a PhotonTransformView script and this is set to the Observe option of the PhotonView.
    The Observe option is set to "Unreliable on Change". If turn it off I get the behaviour I need for the UI Panels, but the movement of the character is no longer synchronized.
    So my question is, can I change the Observe option of the PhotonView by script, during game-play? For example, to switch it from "Unreliable on Change" to "Off" when hitting a collider?

    Thanks
  • vadim
    vadim mod
    edited May 2016
    Options
    You definitely should separate functionality and decouple gui from player object. So that state of player never affects gui state.
    To change gui state, send messages to it when required.
  • TheJangoo
    Options
    I am also having the same problem
  • MadNess
    Options
    So i came across this issue when i had a "chest" that had a photon view to update its opening animation for all players in the game. However the "loot window" only needed to open for the current player that walked up to it. I handled telling the chest to "open" using a trigger collider on the player. Since both the chest and the player had photon views, when telling the loot window to open all players would open it. I could not use the owner of the view of the chest as it was always set to who ever started the room, and would only open the menu for that player in that case no matter who opened it. So to solve this when a player walked up to it i not only passed a variable to trigger the animation (if it wasnt already triggered), i also passed the "lootable" chest the view of the player whos collider hit it, then was able to make it open the correct menu for the right player using:

    if(playerView.IsMine)
    {
    lootwindow.SetActive(true);
    }
  • MadNess
    Options
    FYI im very new to photon, idk if this was ideal but it works