PhotonNetwork.Instantiate error


I'm getting the error: PhotonNetwork error: Could not Instantiate the prefab [cube]. Please verify you have this gameobject in a Resources folder (and not in a subfolder)

That would be easy to fix, but I've already placed the prefab in a Resources folder. See screenshot at the end. the prefab is called "concretecube" and it's properly attached to the script CubeBuilder on gameobject LookObject.

Here's the line I'm getting the error on:
PhotonNetwork.Instantiate( "cube", ( targetblock + hit.normal ), Quaternion.identity, 0);

Other objects in Resources (the player) seem to be instantiated just fine. I've tried treating the prefab as a GameObject rather than a Transform, but that didn't seem to do anything.

Any ideas? Thanks for your help.

Full code -- the line causing the error is at the end.
using UnityEngine;
using System.Collections;

public class CubeBuilder : MonoBehaviour {
	public GameObject mainCamera;
	public Transform cube;
	public Ray ray;
	public RaycastHit hit;

	// Use this for initialization
	void Start () {
		mainCamera = GameObject.FindWithTag("MainCamera").gameObject;

	// Update is called once per frame
	void Update () {
		//Debug.Log ("Camera position " + mainCamera.transform.position);
		//Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		Ray ray = Vector3(0.5f, 0.5f, 0));
		if (Physics.Raycast(ray, out hit, 100)){
        	Debug.DrawLine(ray.origin, hit.point);
			Vector3 targetblock = new Vector3( Mathf.Round(hit.point.x - (hit.normal.x*0.1f)), Mathf.Round(hit.point.y - (hit.normal.y*0.1f)), Mathf.Round(hit.point.z - (hit.normal.z*0.1f)) );
			//print("Hit " + targetblock);
				//evaluating distance separately allows the player to make nice square holes standing in one position
				float removedistancex = (Mathf.Abs(targetblock.x - mainCamera.transform.position.x));
				float removedistancey = (Mathf.Abs(targetblock.y - mainCamera.transform.position.y));
				float removedistancez = (Mathf.Abs(targetblock.z - mainCamera.transform.position.z));
				if ((removedistancex < 5.01f) && (removedistancey < 5.01f) && (removedistancez < 5.01f) && (hit.transform.tag == "Cube") )
					//Debug.Log ("You removed" +;
		    //Adds block only if the distance from the camera to where the block would be added is in a reasonable range
				//evaluates distance of where the new block is (determined by the normal of the ray cast)
				float adddistancex = (Mathf.Abs(targetblock.x + hit.normal.x - mainCamera.transform.position.x));
				float adddistancey = (Mathf.Abs(targetblock.y + hit.normal.y - mainCamera.transform.position.y));
				float adddistancez = (Mathf.Abs(targetblock.z + hit.normal.z - mainCamera.transform.position.z));

				float placementdistance = Vector3.Distance(mainCamera.transform.position + new Vector3(0,-1,0), hit.collider.gameObject.transform.position + hit.normal);
				Debug.Log (placementdistance);
				if ( (placementdistance > 1.1f) && (adddistancex < 5.01f) && (adddistancey < 5.01f) && (adddistancez < 5.01f) && ((hit.transform.tag == "Cube") || ( == "Ground") ) )
					PhotonNetwork.Instantiate( "cube", ( targetblock + hit.normal ), Quaternion.identity, 0);
					//The line below works fine, but isn't transmitted to other players:
					//Instantiate(cube, ( targetblock + hit.normal ), Quaternion.identity);

Direct URL:


  • A little context: I'm trying to create and destroy cubes Minecraft-style. I haven't gotten around to optimizing it into combined chunks yet.

    Is there a better way to be using PUN to do this? Ideally the cubes will be created by any player for all other players, and the current state will be communicated to new players who join the game.
  • Err. None of the prefabs I see in your Resources folder is name "cube". That will be the issue.

    I fear that using PUN instantiation for a minecraft type of game is a receipt for desaster.
    Imagine only a 25*25*25 chunk of space. In worst case, someone joins your game and gets 15625 instantiate calls? This is not going to work for long.
    Also consider bandwidth when you try something like this. Each instantiate call will contain a Transform and the prefab type "cube". This amounts to a lot of data! You need to get rid of the string and positions should not be sent at all. You can map each block to an index in an array.

    Photon is not by default great at transferring a lot of data but instantiations will sum up one by one.
    In best case, you would try to get into server programming with Photon and optimize it to send chunks of data based on a player's position.