PUN 2, OnPhotonInstantiate isn't being called
Options
Hi all,
I was wondering how exactly do I get OnPhotonInstantiate to be called correctly?
What I have right now is a script inheriting from MonoBehaviourPunCallbacks and is subscribed using PhotonNetwork.AddCallbackTarget(this); in an overrided OnEnable as the migration guide suggests. However it isn't being called when a player is being instantiated.
Is there something I am missing?
Thanks.
I was wondering how exactly do I get OnPhotonInstantiate to be called correctly?
What I have right now is a script inheriting from MonoBehaviourPunCallbacks and is subscribed using PhotonNetwork.AddCallbackTarget(this); in an overrided OnEnable as the migration guide suggests. However it isn't being called when a player is being instantiated.
Is there something I am missing?
Thanks.
0
Comments
-
Hi @Vallar,
deriving from MonoBehaviourPunCallbacks is not enough in this case. You would have to implement theIPunInstantiateMagicCallback
as well. Having implemented this, the OnPhotonInstantiate function gets called.0 -
Oh, I see. Thanks @Christian_Simon I thought implementing that would be enough as other callbacks appeared. Will implement the other one. .Christian_Simon said:Hi @Vallar,
deriving from MonoBehaviourPunCallbacks is not enough in this case. You would have to implement theIPunInstantiateMagicCallback
as well. Having implemented this, the OnPhotonInstantiate function gets called.0 -
IPunInstantiateMagicCallback
is different from the other callbacks, because you don't have to register it. Therefore it is not implemented in MonoBehaviourPunCallbacks like other interfaces, for example IConnectionCallbacks or IInRoomCallbacks.0 -
Could you please clarify exactly how one would go about implementing IPunInstantiateMagicCallback? I'm sure I'm just missing some basic unity knowledge about callbacks here, but I can't find info anywhere on how you actually would do that in code!Christian_Simon said:Hi @Vallar,
You would have to implement theIPunInstantiateMagicCallback
as well. Having implemented this, the OnPhotonInstantiate function gets called.0 -
Nevermind, I found a unity tutorial about interfaces and found my answer. For anyone else in my situation...
using UnityEngine; using Photon.Pun; public class MyScriptName: MonoBehaviour, IPunInstantiateMagicCallback { public void OnPhotonInstantiate(Photon.Pun.PhotonMessageInfo info) { // Example... Debug.Log("Is this mine?... "+info.Sender.IsLocal.ToString()); } }
0 -
Still not working for me0
-
Does this script go on the actual gameobject that's instantiated or any gameobject?Alex_P said:Nevermind, I found a unity tutorial about interfaces and found my answer. For anyone else in my situation...
using UnityEngine; using Photon.Pun; public class MyScriptName: MonoBehaviour, IPunInstantiateMagicCallback { public void OnPhotonInstantiate(Photon.Pun.PhotonMessageInfo info) { // Example... Debug.Log("Is this mine?... "+info.Sender.IsLocal.ToString()); } }
EDIT: It looks like it. The PlaymakerGameObjectProxy script has it which needs to be attached to any instantiated object.
But if can only be triggered on that specific gameobject, is there a point to use OnPhotonInstantiate instead of the default Start Class/Event?
Thanks,
jrDev1 -
You can send custom instantiation info to all clients that instantiate said object.0