RaiseEvent OnEvent() not firing
Options
zforest
✭
I'm following
https://doc.photonengine.com/en-us/pun/current/gameplay/instantiation
I made a MonoBehaviour that implements IOnEventCallback and has functions that both calls RaiseEvent, and the OnEvent() function just like the above doc.
Then in my OnEvent(), it is called with event code 255,206,210, etc.. But never goes inside the if() with CustomManualInstantiationEventCode=123
https://doc.photonengine.com/en-us/pun/current/gameplay/instantiation
I made a MonoBehaviour that implements IOnEventCallback and has functions that both calls RaiseEvent, and the OnEvent() function just like the above doc.
Then in my OnEvent(), it is called with event code 255,206,210, etc.. But never goes inside the if() with CustomManualInstantiationEventCode=123
public void OnEvent(EventData photonEvent) { if (photonEvent.Code == CustomManualInstantiationEventCode) {...} }My MonoBehaviour implements IOnEventCallback and has
public void OnEnable() { PhotonNetwork.AddCallbackTarget(this); } public void OnDisable() { PhotonNetwork.RemoveCallbackTarget(this); }
0
Answers
-
Hi @zforest,
Thank you for choosing Photon!
How do you call RaiseEvent?
Do you want to receive events from the same player or from another player? If you want to receive it from the same player who sends the event, you need to set this explicitly as the default behaviour sends event to others e.g.RaiseEventOptions.Receivers = ReceiverGroup.All
.0 -
Hi @zforest,
Do you see anything useful in the logs? warning or error?
Are you calling PhotonNetwork.RaiseEvent when joined to a room? it works only inside rooms.
PhotonNetwork.RaiseEvent returns boolean.
Make sure it returns true.
---Then in my OnEvent(), it is called with event code 255,206,210, etc.The list of event codes.
I can see that 255 is Join event.
Are you connecting to Photon public cloud? which region?
210 is obsolete and should not be received, please make sure you are really receiving this event.
206 is not a predefined native Photon event.
EDIT:
nevermind what's after "---"
210 and 206 are PUN events and not Realtime events:internal class PunEvent { // [...] public const byte SendSerializeReliable = 206; // [...] public const byte OwnershipTransfer = 210;
0 -
I know it's an old one, but if anyone might come here looking for a solution here it is:
You need an IOnEventCallback interface and AddCallbackTarget in OnEnable/OnDisable
public class GameModeManager : MonoBehaviourPunCallbacks, IOnEventCallback { public override void OnEnable() { PhotonNetwork.AddCallbackTarget(this); } public override void OnDisable() { PhotonNetwork.RemoveCallbackTarget(this); } public void OnEvent(EventData photonEvent) { Debug.Log(photonEvent.Code); } }
All here: https://doc.photonengine.com/pun/current/gameplay/rpcsandraiseevent
1