Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Third Party [Photon] HELP! PhotonTargets.AllBuffered Not Working!

Discussion in 'Multiplayer' started by Nsingh13, Aug 2, 2016.

  1. Nsingh13

    Nsingh13

    Joined:
    Dec 17, 2014
    Posts:
    38
    I have an RPC method that sets a pickup object active from an object pool.

    Code (CSharp):
    1. [PunRPC]
    2. public IEnumerator InstantiatePickups()
    3. {
    4. GameObject newPickup =  Pool.GetPooledObject();
    5. newPickup.SetActive (true);
    6.  
    7. yield return new WaitForSeconds (0.1f);
    8.  
    9. Debug.Log("Done");
    10. }
    I then call it when someone kills a player with this:

    Code (CSharp):
    1. scriptthathasthemethod.pv.RPC ("InstantiatePickups", PhotonTargets.AllBuffered);
    This works all well and nice, but when a new player joins the room, the pickup is not set active for him/her. I've been working on this all day and can't figure out what's wrong. Any help is highly appreciated!

    P.s. I'm using Unity 5.3
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,086
    Are you saying InstantiatePickups() doesn't get called?
    If so, make sure the scriptthathasthemethod.pv is existing for the clients that join.
    Also check if you're loading scenes when joining. If the scene finishes loading after you joined, the activated objects get destroyed again and it looks like nothing happened.
     
  3. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    Don't buffer it. The pool should have event system that will send a event to every new player that joins.
    For example You send raiseEvent with true or false and the pickupID so the player will know which pickUP you mean.
     
  4. Nsingh13

    Nsingh13

    Joined:
    Dec 17, 2014
    Posts:
    38
    Ah! That's my problem! scriptthathasthemethod does not exist when a new player joins because player with that script is long dead. So.. I'd have to call the rpc method from a script attached to a gameobject that never goes away. Any easy ways of doing this?

    Thanks for the response!
     
  5. Nsingh13

    Nsingh13

    Joined:
    Dec 17, 2014
    Posts:
    38
    @tobiass Just wanted to let you know that I fixed it by adding another Photonview on a non-player object and then adding scriptthathasthemethod to that particular object. Thank you!
     
    tobiass likes this.
  6. rabarijayesh21

    rabarijayesh21

    Joined:
    Dec 31, 2021
    Posts:
    1
    @tobiass I am using additive scene load and my scene is already loaded before joining the room
    but the problem is that my Allbuffered rpc is not working when new player joins and also getting this errors

    Failed to find a PhotonView with ID=3 for incoming OwnershipUpdate event (newOwnerActorNumber=1), sender=1. If you load scenes, make sure to pause the message queue.
    UnityEngine.Debug:LogErrorFormat (string,object[])
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,086
    PUN is only able to synchronize one scene to load (for everyone). If you have multiple scenes and use buffered RPCs on scene objects, joining players did not load them but still get the RPCs you stored. This is why you get this error.
    You could ignore this but then the RPCs are not executed.

    In general, storing RPCs is not a good approach to store state in a room (for late joiners). Maybe you can use Custom Properties or other.
    Also, PUN is now in Maintenance Mode and won't get new features or improvements. You may want to check out Fusion instead (not knowing it as well, I guess the core problem of getting updates for unknown objects stays the same).