Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Photon call RPC on specific PhotonView or GameObject

Discussion in 'Multiplayer' started by Preen, Jul 1, 2013.

  1. Preen

    Preen

    Joined:
    Jul 1, 2013
    Posts:
    7
    So my bullet flies neatly, and it detects a raycast collision with another photon-instantiated GameObject with a PhotonView. I use the PhotonView owner to determine which client will be affected.

    The hit gameobject (FighterShip) responds by running this function, as expected:


    Ok, awesome. But wait, -I- am the owner of that FighterShip, because it's an AI bot that I spawned. My FighterShip also takes damage, as does any other bot FighterShip that belongs to me.

    So my question, can I filter the recipient of an RPC based on a unique identifier for a specific PhotonView, or a specific Gameobject?

    Thanks
     
    Last edited: Jul 1, 2013
  2. Preen

    Preen

    Joined:
    Jul 1, 2013
    Posts:
    7
    I solved this by giving every spaceship a unique name.

    The RPC is sent to all clients, and executed on all ships. The ship that has a name that matches the argument sent with the RPC will take the damage.

    All clients will see the damage change, and there is no need to update it though a PhotonView.
     
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    A RPC called on a specific PhotonView can be sent to all players or a list of players but the RPC will always get executed on the GameObject that resembles the same object and has the same PhotonView on it. In short: You call the RPC on all of the instances of this specific networked object.

    When you call RPCs on objects you don't own, you can never be sure it's not being destroyed in the same moment you call the RPC. If that happens your RPC might find it's target or not.

    I think you turned things around and are calling the RPC on your own PhotonView and then send the target of the hit. This is actually a good thing to do, because you also control the lifetime of your own PhotonViews.
    I would send the PhotonView.ID as target instead of the target's name. These IDs can be read by you, are unique and shorter than a name.
     
  4. kurtdesi

    kurtdesi

    Joined:
    Dec 10, 2013
    Posts:
    7
    i am having a similar issue that i cant quite figure out ... what i did is iv put a script on the player prefab that says i.. if collision.gameObject.name == "server player " .. debug.log(ismine) , else if collision.gameObject.name == "client player " .. debug.log(ishis) ...... This is working out when the player collides with the clients player ... but is not working out vice versa .. its like no collision is being detected.. PLEASE HELP iv been stuck on this for a week ! I am ready to pay for some help.
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062