[Photon Turnbased] OnEvent() not getting event from OpRaiseEvent

I’m using LoadBalancingClient, and my class derives IPhotonPeerListener.

I wait till ConnectToRegionMaster, OpJoinLobby and OpJoinOrCreateRoom are true.
And they are, I’m using Debug.Log to check.
Service() is on Update().

Then once client is connected to Server/Lobby/Room,
I use this (on Update()):

if (Input.GetKeyDown(KeyCode.B))
{
RaiseEventOptions r = new RaiseEventOptions();
r.Receivers = ReceiverGroup.All;
client.OpRaiseEvent((byte)1, new HashTable(), true, r);
}

But pressing B does nothing.
This is how my OnEvent looks like:

public void OnEvent(EventData eventData)
{
Debug.Log("Event: " + eventData.Code);
}

I would expect to see “Event: 1” on Debug Log,
but it shows nothing. So OnEvent is not receiving the Event.
What could be the problem?

OnEvent is unlike the other callbacks. It might be used a lot, so we decided you should set it up as delegate.
To make PUN use your OnEvent method, do something like this in Start():
PhotonNetwork.OnEventCall += this.OnEvent;

Aparently I don’t have PhotonNetwork.
Forgot to mention I’m using Photon Turnbased not PUN.

So following your example I used client.OnEventAction = this.OnEvent; (Tried with += instead too)
Where client is LoadBalancingClient.

It didn’t worked, BUT client.OnOpResponseAction = this.OnOperationResponse;
did worked (I think) at least now OnOperationResponse is showing something.
Because just like OnEvent, OnOperatoinResponse wasn’t working either.
This is my OnOperationResponse:

public void OnOperationResponse(OperationResponse operationResponse)
{
Debug.Log("OnOperationResponse: " + operationResponse);
}

Almost same as OnEvent.
It shows this on Debug Log now:

OperationResponse 229: ReturnCode: -2.
OperationResponse 226: ReturnCode: -2.
OperationResponse 230: ReturnCode: 0.
OperationResponse 229: ReturnCode: -2.

No idea what it means, but at least it is showing something.
OnEvent tho is not. Any idea?


Edit:

Also, when I press B (refer to the first post)
it shows OperationResponse: 253: ReturnCode: -2. (From OnOperationResponse)
I believe 253 is the correct id for EventRaise, so its being send fine (?) but OnEvent is not getting it (?)

I finally managed to make it work.
Problem was I wasn’t really connected to the server and room properly.
I changed the connection code and once I was inside the room properly OnEvent worked fine.
I tested it with 2 clients (Editor + Build for Windows) and both received the events fine.

2 Likes