Filter Players in the game screen at runtime

Hi ,
I have a game where about 20 users join in a room.
They have some properties like gender, name, isFriend etc.

Now I want to filter (display) only those users on the screen who fulfil a particular criteria at runtime (when all the user's have joined a room).

Just wanted to know whether this is possible?

Any help would be appreciated.

Thanks,

Comments

  • What's the criterion? A criterion is a property of the player. And so the criterion by looking at the properties of all players will display the necessary ones for which the criterion property = true
  • "particular criteria" here means that I want only those players in the screen (as following)
    1. whose gender are males.
    2. Gender is female.
    3. Who are in close proximity of say 100 meters.
    4. Who are friends
    5. who are not friends.
  • Hi @sid_juego,

    you can use the Player Properties to store this kind of data. This way it is also available for each other client and each client can check locally which GameObjects should be enabled or disabled based on certain criteria. Maybe this code snippet gives you an idea where and how to start:
    foreach (PhotonView pView in FindObjectsOfType<PhotonView>())
    {
        if (pView.isMine)
        {
            continue;
        }
    
        if (pView.owner.CustomProperties.ContainsKey("gender"))
        {
            pView.gameObject.SetActive(pView.owner.CustomProperties["gender"] == "f");
        }
    }
  • Hi @sid_juego,

    you can use the Player Properties to store this kind of data. This way it is also available for each other client and each client can check locally which GameObjects should be enabled or disabled based on certain criteria. Maybe this code snippet gives you an idea where and how to start:

    foreach (PhotonView pView in FindObjectsOfType<PhotonView>())
    {
        if (pView.isMine)
        {
            continue;
        }
    
        if (pView.owner.CustomProperties.ContainsKey("gender"))
        {
            pView.gameObject.SetActive(pView.owner.CustomProperties["gender"] == "f");
        }
    }

    Are you sure that this is the correct way to do it?
    What if some other photon player changes it positioned tries to send a rpc call? Will this work?
  • @chvetsov Is this the correct way to do it?
    Apologies for adding you like this in the thread.
  • @sid_juego i have knowlege mostly about server side. I've say sorry, i can not give a hint. but i'm sure @Christian_Simon gave you correct answer. just try it. if it does not work then you will be able to find different solution

    best,
    ilya
  • @Christian_Simon This approach will work fine but every player that is inside a room has a PhotonAnimatorView attached to it. As a result of which i am getting this error.

    "Animator has not been initialised." Any clues?
  • When do you get this error? When launching the game, after instantiation, after enabling / disabling the game object? Does it happen more or less regularly?

    In case this happens when disabling and enabling the game object, try to only enable / disable rendering and colliding components (e.g. Mesh Renderer and Mesh Collider) instead of the whole game object.
  • sid_juegosid_juego
    edited June 19
    1. When do you get this error?
    After launching the game, when game object gets instantiated and disabling the game objects in between.

    2. Does it happen more or less regularly?
    its happens regularly.

    3. try to only enable / disable rendering and colliding components (e.g. Mesh Renderer and Mesh Collider) instead of the whole game object
    Well I can do that but either ways I have to get the reference every mesh renderer and collider or use GetComponentsInChildren.


    Now, I've removed PhotonAnimatorView and I'm animating my game objects locally based on their last position. After doing this, the warning is gone.
    The reason behind this was the other client doesn't know that its game object has been disabled in some other device, so as per PhotonAnimatorView, it will keep on sending the updated animation data to all of its photon view on other devices.
Sign In or Register to comment.