AR Foundation and PUN2

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

AR Foundation and PUN2

Boston_Developer_1
2022-03-20 13:38:38

Hi!,

I have built product using the AR Foundation and I have used PUN2 a number of times. So I have a bunch of code to build upon to create a PUN2-AR Foundation application.

An AR scene should include an ARSession component. An AR session is a global construct. An ARSession component manages this global session, so multiple ARSession components will all try to manage the same global session. So it does not appear that AR Foundation like multi-scene games.

In Pun2, in most of the code where I have built uses a Quickstart scene to get the nickname and other player preferences. And then we launch into the game which is the second scene. If this is the Master Pun - then we PhotonNetwork.LoadLevel(SceneNumber);

So I made several attempts to integrate these two - AR Foundation and PUN2 with some success but also we some really strange behavior. Maybe these two were not meant to be integrated like this.

So Could you provide:

  1. Input on the strategy that I am using. Will this work in the end?

  2. Is there an example of how to implement? AR Foundation likes single scene and PUN2 likes multi-scene. Which one should I try to change?

  3. Know restrictions. I have seen instructions for HoloLens but is not my goal.

thanks

Herb Rush

Comments

Boston_Developer_1
2022-03-27 23:32:52

Anyone have any Suggestions about this integration? Thanks Herb Rush

Tobias
2022-03-28 14:54:47

PUN 2 does not care if you use a single scene or many.

You could put your UI on top of the usual scene, edit your nickname and other values as you like.

I actually don't know of any issues why PUN 2 should not run with AR.

Boston_Developer_1
2022-03-28 15:14:10

Ok. AR does not seem to want to have multiple Scenes. Reality is like the only scene it supports. I could setup the nickname, lobby and room stuff and then do PhotonNetwork.LoadLevel(0) from the Master to get started. I am going to bet that works with AR and AR multiplayer. What about WebGL and AR multi-player? This big difference with AR is the "Main Camera" is not there. The Head Set or the iPhone is the camera and they have something called AR Session and AR Session Origin instead. I am willing to spend some time to try this out if you think I have a reasonable chance of success.

Boston_Developer_1
2022-03-28 20:10:52

I chopped anAR project and put in the nickname, lobby, room stuff, and did the LoadLevel(0). It works but it looks like the AR Scene and all the stuff in it is reloaded after the LoadLevel(). I get an avatar etc... This is not ideal but I guess I can work around. So to get this to work with a NON AR Unity project. I would basically run it the same way with everything in single scene and the master client does the LoadLevel(0) and the photon views should be aligned. The scenes will have the same name but they won't be the same scenes - one is an AR Scene and the other is a Non-AR Scene. Sound about right? Any Suggestions? Thanks.

Boston_Developer_1
2022-03-29 13:33:13

I start the AR side first. Which is the master client. Starts ok but this single scene that is loaded is messing up some of my other stuff.  Anyway, I start a very similar scene in the Unity Editor and it starts ok. I get a photon network player and Player Avatar for the local and remote characters. See attached.

The local one looks fine. The remote one has NO avatar attached because I only get one RPC_ADDCHARACTER for the local one - not the remote. So the local looks good but the remote is a transparent capsule.

It looks like the RPC mechanism is messed up. Likely due to some other issue.

I see the same thing on the AR side. Local is good but remote is missing.

RPC complains about: This code works fine on the local version.

  • RPC method 'NameTheObject(Int32)' not found on object with PhotonView 1002. Implement as non-static. Apply [PunRPC]. Components on children are not found. Return type must be void or IEnumerator (if you enable RunRpcCoroutines). RPCs are a one-way message

  • And a RPC that I have but don’t use called StartDance IS called.

I really cannot go any further without some sort of guidance. I don't know what I am looking at.

See attached.

AR Problem.png

Uploaded 2022-03-29T13:31:34+00:00 31126 bytes

Herb Rush

Back to top