Player Avatar wont spawn when joining a room

Hello , i was going through a tutorial https://www.youtube.com/watch?v=93SkbMpWCGo . all went really good got the menu setup to join & create rooms. according to photons traffic it does appear that i am able to get multiple people in the same room so thats not the problem. The problem comes when trying to spawn in the players avatar nothing appears

here is the script for spawning the prefab when a player joins a room.


  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Photon.Pun;
  5. public class SpawnPlayers : MonoBehaviour
  6. {
  7. // Start is called before the first frame update
  8. public GameObject playerPrefab;
  9. public float minX;
  10. public float maxX;
  11. public float minY;
  12. public float maxY;
  13. private void start()
  14. {
  15. Vector2 randomPosition = new Vector2(Random.Range(minX, maxX), Random.Range(minY, maxY));
  16. PhotonNetwork.Instantiate(playerPrefab.name, randomPosition, Quaternion.identity);
  17. }
  18. }

i can join and create rooms fine - players prefab do not spawn. no compile errors or errors while running project.

Answers

  • Try this:

    PhotonNetwork.Instantiate(playerPrefab, randomPosition, Quaternion.identity);
    
  • @Nexo i get this error when i replaced the line of code with the one you provided


    Assets\SpawnPlayers.cs(19,35): error CS1503: Argument 1: cannot convert from 'UnityEngine.GameObject' to 'string'

  • The prefab parameter has to be a string. It's the name of a prefab.

    This is covered in the PUN Basics Tutorial and the docs in general.