Raise event not getting called

Hello for some reason the raise event does not call On Event at all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
using Photon.Realtime;
using Photon.Pun;
using ExitGames.Client.Photon;
public class TestRaiseEvent : MonoBehaviourPun
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.B))
        {
            RaiseEvent();
        }
    }

    void RaiseEvent()
    {
        Debug.Log("RAISE EVENT");

        byte evCode = 0; // Custom Event 0: Used as "MoveUnitsToTargetPosition" event
        object[] content = new object[] { new Vector3(10.0f, 2.0f, 5.0f), 1, 2, 5, 10 }; // Array contains the target position and the IDs of the selected units
        RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.All }; // You would have to set the Receivers to All in order to receive this event on the local client as well
        SendOptions sendOptions = new SendOptions { Reliability = true };
        PhotonNetwork.RaiseEvent(evCode, content, raiseEventOptions, sendOptions);
    }

    public void OnEvent(EventData photonEvent)
    {
        byte eventCode = photonEvent.Code;

        Debug.Log("ON EVENT");

        if (eventCode == 0)
        {
            Debug.Log("EVENT CODE MATCHED");
        }
    }

    public void OnEnable()
    {

        PhotonNetwork.AddCallbackTarget(this);
    }

    public void OnDisable()
    {
        PhotonNetwork.RemoveCallbackTarget(this);
    }
}

Comments

  • JohnTubeJohnTube mod
    edited June 19
    Hi @Mashman12,

    You need to explicitly state which callbacks interface you are implementing for the registration to work:
    replace:
    public class TestRaiseEvent : MonoBehaviourPun
    with:
    public class TestRaiseEvent : MonoBehaviourPun, IOnEventCallback
Sign In or Register to comment.