Photon.Monobehaviour vs. Photon.PunBehaviour

I’m working on a simple PUN tutorial and for the most part we replace Monobehaviour with PunBehaviour. At one part, however, the say to change Monobehaviour to Photon.Monobehaviour.

Can anyone help me understand why we just don’t always use PunBehaviour? Thanks.

Did you have a look at the code?
PunBehaviour is a Photon.MonoBehaviour and adds (empty) implementations for the IPunCallbacks. This is making the class a bit bigger/heavier, which is usually not a problem but for some cases it might make sense to avoid it. It can also help separating scripts that are planned to get callbacks (PunBehaviour) from those that should not get IPunCallbacks. There is an option to set the specific type in PhotonNetwork.SendMonoMessageTargetType.

@tobiass , OK, that makes sense and it may answer another question that I have. Something that I found frustrating in following the tutorial was that there was no intellisense for the PUN callbacks. Therefore, a typo simply results in a new method (C# doesn’t care). In my case, part of the method included “Requested” but I just wrote “Request” and it was really difficult to find. Therefore, if I inherit from PunBehaviour, will I get intellisense autocomplete for the callback methods?

P.S. I’ll be away from my computer today so I can’t test this myself. Thanks for your help.

Yes, that’s exactly the reason for the PunBehaviour. Also, implementing the interface makes sense, because the actual calling of the callbacks in an interface is multiple times faster than mono messages.

1 Like

@tobiass Thanks for clearing that up. I went back to one of my classes that has PUN callbacks in it, but derives from the standard MonoBehaviour, and changed that to PunBehaviour. As you said, VS intellisense now shows the PUN callbacks. What’s interesting is that I now get a warning that my PUN callbacks hide the PunBehaviour ones, and that I need to use the override keyword. So why is normal OO behaviour confusing, you ask? Unity doesn’t require the use of the override keyword, but I think I read that Photon Bolt does use it. Is it also required for PUN, or am I doing something wrong?

It still feels strange to implement overridden methods that don’t require either inheritance or a “using” statement.

Sorry, I made a mistake in my last post; the PUN callbacks do NOT show up in intellisense. The warning to use “override” is still there, so VS does know about the methods.

Just use the override keyword. It’s the C# way of doing things.
I’m not sure how Unity gets intellisense without the override. It might be a method-name dictionary in a plugin or such.