PhotonNetwork.RaiseEvent() help

Options
I am familiar with the PunRPC process (how to use them) as well as Events and delegates in unity. I do not understand how to take a function for an object in unity(local) and send that to a photonNetwork using RaiseEvent. Im attempting to instantiate an object in a room on the photon network without using a PhotonView so i need to understand the raiseEvent method... I cant find any great tutorials on how the (byte, byte[], reliable,) arguments relate to a function ive written for an object or how to use RaiseEvent with already written object functions. Are there any good tutorials on instantiate/move/etc functions using RaiseEvent?

Comments

  • Hi @LaundryOnMyAbs,

    there is an section about Manual Instantiation at the bottom of this documentation page. You can use that and replace the RPC call with a RaiseEvent call.
    // RaiseEvent call
    string prefabPathAndName = "PrefabPathAndName";
    Vector3 position = Vector3.zero;
    Quaternion rotation = Quaternion.identity;
    
    PhotonNetwork.RaiseEvent(InstantiationEventCode, new object[] { prefabPathAndName, position, rotation }, true, new RaiseEventOptions() { Receivers = ReceiverGroup.All, CachingOption = EventCaching.AddToRoomCache });
    // OnEvent call
    private void OnEvent(byte eventcode, object content, int senderid)
    {
        if (eventcode == InstantiationEventCode)
        {
            object[] data = (object[])content;
    
            string prefabPathAndName = (string)data[0];
            Vector3 position = (Vector3)data[1];
            Quaternion rotation = (Quaternion)data[2];
    
            Instantiate(Resources.Load(prefabPathAndName), position, rotation);
        }
    }