Oculus Avatar with PUN2

Hi there,

I'm new with Photon and I've just learnt the basic with the tutorial.

However, I'm stuck when I want to use the Oculus Avatar tutorial described here:


In the following part, the PhotonNetwork.AllocateViewID() method in PUN2 is taking a PhotonView as a parameter, and return a bool instead of an int.

How can I modify this code to work with PUN2? Am I missing something?

public void OnJoinedRoom()
int viewId = PhotonNetwork.AllocateViewID();

RaiseEventOptions raiseEventOptions = new RaiseEventOptions
CachingOption = EventCaching.AddToRoomCache,
Receivers = ReceiverGroup.All

SendOptions sendOptions = new SendOptions
Reliability = true

PhotonNetwork.RaiseEvent(InstantiateVrAvatarEventCode, viewId, raiseEventOptions, sendOptions);

Thanks in advance for your help!


  • Hi @citron,

    thank your for the hint. I'm going to update this page soon.

    In the meantime the new workflow should look similar to the following steps:
    1. In the OnJoinedRoom callback you would have to instantiate your avatar locally by using GameObject avatar = Instantiate(...);
    2. Then you need a reference to its PhotonView component, for example PhotonView photonView = avatar.GetComponent<PhotonView>();
    3. You can pass this reference as parameter in PhotonNetwork.AllocateViewID(photonView);
    4. Since you already have instantiated the avatar locally, you don't have to send this event to All any longer. So when creating the RaiseEventOptions you can use Receivers = ReceiverGroup.Others
    5. When finally raising the event, you want to use photonView.ViewID instead of viewId
    You would also make some changes to the OnEvent callback:
    • Instead of checking if you have to instantiate a Local or Remote Avatar, you can always instantiate the Remote Avatar (it can't be a Local Avatar)
    • Assign the ViewId received with the event to the newly instantiated Remote Avatar (looks similar to the code snippet on the documentation page.
  • Thanks a lot!
Sign In or Register to comment.