RaiseEvent OnEvent() not firing
The whole answer can be found below.
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).
RaiseEvent OnEvent() not firing
zforest
2019-03-30 19:54:38
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
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);
}
Comments
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
.
hi @JohnTube
I followed the guide and used ReceiverGroup.Others
when that did not work, I also tried ReceiverGroup.All
but no dice either. Would be good if there is a way to debug this. Thanks
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.
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;
MeatyMario
2023-02-18 03:31:27
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
Back to top