2

I'm trying to create a simple VR demo where two users can connect to a room a manipulate objects on a table. I'm currently following this tutorial.

I have followed it step-by-step:

  • Duplicated LocalAvatar and RemoteAvatar prefabs and moved them to Resources

    Created the script PhotonAvatarView Script

    Attached and configured PhotonAvarView and PhotonView to both prefabs

The problem is that I get stuck at the "Instantiate Avatars" section, specifically at the section:

The following code can be placed for example in your already existing Network Manager or any other script that already deals with network logic, it doesn't belong to the PhotonAvatarView script we created earlier. Here we are using the OnJoinedRoom callback.

My assumption is that this is a tutorial from scratch (given the way it starts with a blank Unity project), but I don't have any Network Manager script in place so I'm a bit confused. Putting that code into a new script and just attaching it to an object doesn't seem working.

Am I missing some parts?

Kaiserludi
  • 2,434
  • 2
  • 23
  • 41
Claus
  • 5,662
  • 10
  • 77
  • 118
  • So... is your question *What is this thing that the tutorial refers to, but doesn't explain?* – Mars Sep 09 '19 at 09:53
  • The network manager is a singleton that you would usually have in your project to be the hub of your networking. If the tutorial doesn't explain it, or at least give you a demo one, then you probably want to try another tutorial. – Mars Sep 09 '19 at 09:55
  • Hi Claus, the link to the tutorial you mentioned here is not active anymore. Do you know where they moved it to? I cannot find another PUN Oculus Avatar tutorial. – Towerss Feb 21 '21 at 09:05

1 Answers1

2

We got your feedback and the tutorial will be reviewed and updated based on this.

To help you with your issue and answer your question:

The NetworkManager you need in this case and following the tutorials in whole needs to implement two PUN2 callbacks: IMatchmakingCallbacks.OnJoinedRoom and IOnEventCallback.OnEvent. While the tutorial may suggest that there could be two separate classes one implementing each callback (NetworkManager and MyClass), there is nothing against grouping them in one place. In the tutorial's "Instantiating Avatars" section's first code block, we see that the OnJoinedRoom method is overridden. This probably means that the original writer assumed that the NetworkManager must be extending MonoBehaviourPunCallbacks class. Inheriting from MonoBehaviourPunCallbacks class is the easiest and fastest way to implement PUN2 callbacks: it's a MonoBehaviour that allows you to selectively override the callbacks you need and only those you need, it already handles callbacks registration and deregistration on your behalf (respectively in OnEnable and OnDisable) it does not require having to remember all the callbacks' interfaces and it also extends MonoBehaviourPun which exposes the PhotonView easily in a property if the latter is attached to the same GameObject. However, you should be careful as it does not implement all callbacks interfaces but most. It implements IConnectionCallbacks, IMatchmakingCallbacks, IInRoomCallbacks, ILobbyCallbacks and IWebRpcCallback. It does not implement IOnEventCallback, IPunInstantiateMagicCallback, IPunObservable and IPunOwnershipCallbacks. PUN2's utility interfaces are also not implemented e.g. IPunTurnManagerCallbacks.

Talk is cheap, show me the code:

public class NetworkManager : MonoBehaviour, IMatchmakingCallbacks, IOnEventCallback
{
    public const byte InstantiateVrAvatarEventCode = 1;

    public void OnJoinedRoom() // w/o override
    {
        // code from the tutorial here
    }

    public void OnEvent(EventData photonEvent)
    {
        // code from the tutorial here
    }

    private void OnEnable()
    {
        PhotonNetwork.AddCallbackTarget(this);
    }

    private void OnDisable()
    {
        PhotonNetwork.RemoveCallbackTarget(this);
    }

    #region Unused IMatchmakingCallbacks

    public void OnFriendListUpdate(List<FriendInfo> friendList)
    {
    }

    public void OnCreatedRoom()
    {
    }

    public void OnCreateRoomFailed(short returnCode, string message)
    {
    }

    public void OnJoinRoomFailed(short returnCode, string message)
    {
    }

    public void OnJoinRandomFailed(short returnCode, string message)
    {
    }

    public void OnLeftRoom()
    {
    }

    #endregion
}
JohnTube
  • 1,782
  • 27
  • 46
  • 1
    Thanks, I was about to update the question with the link to the tutorial which explain how to setup the whole thing (https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/lobby). It's my understanding you work for Photon, in this case I would kindly ask you to create a tutorial specifically for VR projects with Unity. Including manipulating grabbable rigid bodies in a room while keeping everything in sync. Your documentation is great but sometimes feels a bit too advanced. A step-by-step document accessible to all levels would be perfect! – Claus Sep 10 '19 at 12:14
  • OK. I will forward your request for a step-by-step guide for doing VR with PUN to the right team. Thanks for your feedback. – JohnTube Sep 10 '19 at 13:42
  • Hey @JohnTube, the link to the tutorial mentioned in the question is not active anymore. Do you know where they moved it to? I cannot find another PUN Oculus Avatar tutorial. – Towerss Feb 21 '21 at 09:06
  • 1
    Unfortunately the tutorial is not available anymore. I hope you can find some other tutorial online. – JohnTube Feb 21 '21 at 14:21