Missing something with RaiseEvent setup?

Options
Here is where we register our test event:
public class GameEventHandler : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
		if (PhotonNetwork.isMasterClient){
			Debug.Log("OnEventRaised registered.");
			PhotonNetwork.OnEventCall += this.OnEventRaised;
		}
		
	}
	
	public void OnEventRaised(byte eventCode, object content, int senderID){
	
		Debug.Log(string.Format("OnEventRaised: {0}, {1}, {2}", eventCode, content, senderID));
	}

}

Here is where we attempt to trigger the eventhandler:
public void PrimaryAction(){
		
		if (this.shotTimer >= this.shotDelay){
			audio.Play();
			this.shotTimer = 0.0f;
			Ray mouseRay = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
			RaycastHit hitInfo;
			if (Physics.Raycast(mouseRay, out hitInfo)){
				PhotonNetwork.RaiseEvent((byte)GameEventCode.TestEvent, "blank content?", true, RaiseEventOptions.Default);
                                Debug.Log("RaisEvent called");
			}
			Transform camera = transform.Find("MainCamera");
			camera.RotateAround(transform.position, transform.right, -1.0f);
			this.lastGunAimPos = camera.localEulerAngles;
		}

	}

First off, using debug.log we've verified that the eventhandler is getting registered on the master client, and that the block where PhotonNetwork.RaiseEvent is executing, but OnEventRaised never gets called.
Secondly, the API doc states the 4th argument is a PhotonPlayer type, but it's actually requiring and int. Third, the object eventContent is supposed to be optional, but if there isn't something there the game won't compile because there's no overload for RaiseEvent with 3 arguments. Anyway, the first issue is the most important so no worries about the other two... If more info is needed please ask, but according to the docs this should be working.

Comments

  • vadim
    Options
    Your code looks ok except that PhotonNetwork.isMasterClient is not always defined when Start() called. But looks like it is in your case.

    What is value of GameEventCode.TestEvent? It should be < 200.
    Make sure that you call event from non-master client since only master receives and events are not sent to client itself by default.

    Currently PhotonNetwork has only one RaiseEvent method:
    void RaiseEvent(byte eventCode, object eventContent, bool sendReliable, RaiseEventOptions options);
    Set eventContent = null to skip content.
    Use 4th parameter for setting RaiseEvent options.
  • Tobias
    Options
    I will update the RaiseEvent documentation for the next release. The RaiseEventOptions are not optional as parameter but can be null.
    I will also check the other pieces.

    Let us know what your event code is. This should be the only place where it can go wrong. Anything in the logs?
  • PhotonNetwork.isMasterClient is not always defined when Start() called. But looks like it is in your case.
    Ya, we figured that out the hard way. What event triggers the isMasterClient bool to be set? I would also recommend it be documented what handles this. We struggled for quite a while before we narrowed it down to that bool being false. Super baffling when it's false at the beginning of the second and true at the end. :P
    What is value of GameEventCode.TestEvent? It should be < 200.
    It's a enum we cast to a byte. There's just one for now so it's at the default 0. Documentation says 1-199 I think so does this need to start from 1?
    Make sure that you call event from non-master client since only master receives and events are not sent to client itself by default.
    Woah really? By default... how do we change this behavior? We were testing with 2 clients but things might have been working and we didn't know. We were watching for the debug statements on the MasterClient. I'll verify this, but I'd love to change this default behavior. I can't actually see a case where this is useful. What is the intended purpose for not raising the event on the local client? I'm guessing to give it some variance from RPCs?
  • vadim
    Options
    1. Client can't figure out is it master or not until it enters the room. So wait for OnJoinedRoom message.
    2. Use any byte form 1-199 range
    3. By default event sent to all clients except sender (PhotonTargets.Others). This saves bandwidth and makes sender more responsive to it's events (if it handles events at send time). Set RaiseEventOptions.Receivers to PhotonTargets.All for sending to all clients including sender.
    Note: you may try debugging events w/o PhotonNetwork.isMasterClient filter first since this is possible reason for at least two issues in your code (p 1. and 3.)