0

I have a iOS App created with React-Native that includes a Unity app that may be opened and closed several times during the use of the React-Native app.

The Unity app has a Photon Pun. All works very well the first time we open the Unity app.

But the Photon Pun does not connect properly to the master server the second time one opens Unity within the same process.

I figured out that the internal class PhotonHandler gets started and enabled when we first start Unity. It gets disabled when we stop Unity. But then it never enables again. The problem is maybe that the enabling happens through the constructor of PhotonNetwork. This is the stack trace:

Photon.Pun.PhotonHandler:OnEnable()
UnityEngine.GameObject:AddComponent()
Photon.Pun.PhotonHandler:get_Instance()
Photon.Pun.PhotonNetwork:StaticReset()
Photon.Pun.PhotonNetwork:.cctor()
PhotonManager:OnEnable()

Components get added and enabled in constructors and disabled when we run unloadApplication. But many game objects then remain disabled when we start Unity again because all instances are already created.

How can I enable them again?

A little bit of background

Unity is exported for iOS, built and the resulting UnityFramework is embedded into the iOS app.

We then start unity using unityFramework.runEmbedded(withArgc: CommandLine.argc, argv: CommandLine.unsafeArgv, appLaunchOpts: [:])

How we solved it on android

On Android we are able to start unity in a separate process and then completely kill this process while the main app keeps running. The problem disappeared there as soon as we did that.

I am happy for every little hint.

romixch
  • 580
  • 4
  • 12
  • Does your app disconnect from the photon server before you unload unity? – hijinxbassist Dec 01 '22 at 23:00
  • Yes. I tried that. It worked in the unity simulator but it did not work on the iPhone device itself. – romixch Dec 02 '22 at 07:29
  • I found out that the PhotonHandler somehow does not get enabled again after `unloadApplication`. – romixch Dec 02 '22 at 21:04
  • @hijinxbassist I updated my question. I figured out why that happens. But I don't know how I can work around this IMO bug of Photon. – romixch Dec 02 '22 at 21:41
  • 1
    Maybe one of the function of PhotonNetwork will reinitialize it if it determines the request isn't being made. I imagine you are reconnecting the server each time you run the unity app using connect using settings right? Try getting the server timestamp or using one of the other functions that require a server request to complete. – hijinxbassist Dec 02 '22 at 22:09
  • Yes. We reconnect when we start. From reading their code I can not see how they could reinitialize. I also asked on their forum and hope to get a developer. Im quite pessimistic right now that I can fix that in a propper way without a bug fix from their side. – romixch Dec 03 '22 at 23:29
  • 1
    The solution is likely similar to how you solved it for android. I personally do not have knowledge on ios development though. Check for information related to fully terminating sub processes, or encapsulating them so you can terminate it. I imagine the way ios handles the processes is different and that is why your android solution was not valid for that environment? – hijinxbassist Dec 04 '22 at 18:35
  • First thanks for still keep helping me! The implementation with two processes on android was quite "easy". Android provides the ability to open an activity (a GUI screen) in a new process. I then only had to make sure that there is some interprocess communication. Done. On iOS I saw that I can fork processes. But I am not sure about grabbing the display and about interprocess communication. – romixch Dec 04 '22 at 22:41
  • Moreover I could not find anyone who does exactly that on iOS. It seams to be not an easy task. Especially to me that is not an iOS expert. – romixch Dec 04 '22 at 22:46

0 Answers0