Instantiate Aiplane Client is not the MasterClient in the room

Options

Failed to InstantiateSceneObject prefab. AirPlane, Client is not the MasterClient in the room

image and script below:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FlareAirDrop : MonoBehaviour {

	public GameObject AirPlane;
	public GameObject AirDrop;
	public float speed;
	private bool suport = false;
	public PhotonView photonView;
	private bool suport2 = false;

	[PunRPC]
	public void Airplanespawn (){

		AirPlane = PhotonNetwork.InstantiateSceneObject ("AirPlane", new Vector3 (Random.Range (-1000, 1000), 230, -100), Quaternion.identity, 0, null) as GameObject;

		Vector3 relativePos = AirPlane.transform.position - transform.position;
		Quaternion rotation = Quaternion.LookRotation(relativePos);
		AirPlane.transform.rotation = rotation;
	}

	[PunRPC]
	public void airdropspawn (){

		AirDrop = PhotonNetwork.InstantiateSceneObject ("AirDrop", new Vector3 (AirPlane.transform.position.x, AirPlane.transform.position.y - 10, AirPlane.transform.position.z), Quaternion.identity, 0, null) as GameObject;

	}

	void Update () {

		if (Input.GetKeyDown ("e")) {

			if (photonView.isMine) {
				gameObject.GetComponent<PhotonView> ().RPC ("Airplanespawn", PhotonTargets.All, null);
				suport2 = true;
			}
		}

		float step = speed * Time.deltaTime;

		if (suport == false && suport2 == true) {

			AirPlane.transform.position = Vector3.MoveTowards (AirPlane.transform.position, new Vector3 (transform.position.x, 230, transform.position.z), step);
		
		}  

		if (suport == true) {
			
			AirPlane.transform.Translate (0, 0.2f, -step);

		}

		if (AirPlane.transform.position.z >= transform.position.z && suport == false) {

				suport = true;
				suport2 = true;
				Debug.LogAssertionFormat ("AirDroped");
				photonView.RPC ("airdropspawn", PhotonTargets.All, null);

			}
		}
	}
https://uploaddeimagens.com.br/imagens/sdawdw-png

Comments

  • TyHover
    Options
    help =/
  • WTler
    Options
    I think I had a similar problem last week. If you instantiate a scene object, only the master client runs
    AirPlane = PhotonNetwork.InstantiateSceneObject ("AirPlane", new Vector3 (Random.Range (-1000, 1000), 230, -100), Quaternion.identity, 0, null) as GameObject;. The other Clients do not get the information that AirPlane is your instantiated object. To solve this you can add a script to your AirPlane prefab with the method
    void OnPhotonInstantiate(PhotonMessageInfo info)
        {
            
        }
    With FindObjectsOfType<FlareAirDrop>.AirPlane you can get your AirPlane Object if I'm not totally wrong. I hope that it solves your problem
  • TyHover
    TyHover
    edited July 2017
    Options
    I tried this:
    void OnPhotonInstantiate(PhotonMessageInfo info)
    	{
    		FlareAirDrop myObject = GameObject.FindObjectOfType<FlareAirDrop>();
    		myObject.AirPlane = gameObject;
    
    	}
    
    But I guess:

    void OnPhotonInstantiate(PhotonMessageInfo info)

    It is for when the object is instantiated, this is the problem the player who is not masterclient can not instantiate the object.

  • OnPhotonInstantiate is only processed if the game object (with the attached OnPhotonInstantiate script) is instantiated through any PhotonNetwork.Instantiate(SceneObject) call.

    Please note: PhotonNetwork.InstantiateSceneObject can only be called by the MasterClient, if you want non-MasterClients to instantiate networked prefabs use PhotonNetwork.Instantiate instead.
  • TyHover
    Options

    OnPhotonInstantiate is only processed if the game object (with the attached OnPhotonInstantiate script) is instantiated through any PhotonNetwork.Instantiate(SceneObject) call.

    Please note: PhotonNetwork.InstantiateSceneObject can only be called by the MasterClient, if you want non-MasterClients to instantiate networked prefabs use PhotonNetwork.Instantiate instead.

    I tried:
    	[PunRPC]
    	public void airdropspawn (){
    
    		AirDrop = PhotonNetwork.Instantiate ("AirDrop", new Vector3 (AirPlane.transform.position.x, AirPlane.transform.position.y - 10, AirPlane.transform.position.z), Quaternion.identity, 0, null) as GameObject;
    
    	}
    but, no results
  • Make sure that the RPC is actually called on at least one client. You can do this by Debug Logging for example. Also check if it throws any kind of warning or error. Is this RPC only send to the MasterClient or to every client in the room? If it is send to each client, everyone will call PhotonNetwork.Instantiate resulting in a lot of Instantiation calls, so please make sure that this is the correct behaviour.