- Home /
Photon: Please verify you have this gameobject in a Resources folder (and not in a subfolder)
So I'm trying to get multiplayer in my game with Photon. But the player prefab that needs to be loaded wont load with the error: PhotonNetwork error: Could not Instantiate the prefab [YouTwo (UnityEngine.Transform)]. Please verify you have this gameobject in a Resources folder (and not in a subfolder)
So I put the prefab in a new folder I called Resources. And it still wont work. There is not sub-directories, and the Resources folder is in the root of the assets folder.
Any help is greatly appriciated. If you need some more info to help please just say so.
That is strange. Could you post the line of code you are using to instantiate your player?
public Transform playerPrefab;
void OnJoinedRoom ()
{
PhotonNetwork.Instantiate(playerPrefab.ToString(), transform.position, Quaternion.identity, 0);
}
print(playerPrefab.ToString());//you might find this to be not what you were expecting it to be.
The string should be the name of your prefab, letter for letter. Prefabs are GameObjects. And I don't think transforms have names but I could be wrong. GameObjects have names that's for sure.
Transforms as well as all other components share the same name as the Gameobject, however ToString won't return the name AFAI$$anonymous$$ but would return something like "UnityEngine.Transform".
Yes that's right. GameObject is a property of pretty much all monobehaviors and quite a few components too. You can do transform.gameObject.GetComponent().gameObject.name and similar insane things. Actually it does come in handy.
Answer by Bunny83 · Aug 08, 2013 at 04:41 PM
Photon can't instantiate a prefab like Network.Instantiate does. Photon requires you to place your prefab in an Resources folder. When you call PhotonNetwork.Instantiate you have to pass the name of the prefab to the function. Like i said in the comment above. ToString won't return the name.
If you have the prefab you bound to the "playerPrefab" variable in a Resources folder, just try this:
PhotonNetwork.Instantiate(playerPrefab.name, transform.position, Quaternion.identity, 0);
It seems like it needs to be in a folder called Resources without a subfolder, so either: Resources/YouTwo.prefab
or Resources/Characters/Resources/YouTwo.prefab
$$anonymous$$inda weird that Resources/Characters/YouTwo.prefab
is not working, which seems to work for other similar Unity operations.
Answer by Info-Gamer · Nov 12, 2020 at 04:48 AM
Here is a helpful video for if ever you get this error when your prefab is already in the Resources folder
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Which kind of error can cause a silent crash? 0 Answers
Network.Connect failed. 1 Answer
Method Not Found: 'Network.InitalizeServer' 0 Answers
attached prefabs before client joins 2 Answers