Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Clones in Unity not appearing in game view

Discussion in 'Editor & General Support' started by coquelicotqc, Mar 9, 2022.

  1. coquelicotqc

    coquelicotqc

    Joined:
    Aug 24, 2021
    Posts:
    3
    Hi, I just started learning game development with unity and I just ran into a problem. I created a spawner and the clones don’t appear in game view. It is really strange because the clones appear in the hierarchy and in the scene view. Their Box Colliders work so the character you play gets pushed by the clones, even if they are invisible.

    Here is my code for the spawner:

    public class MonsterSpawner : MonoBehaviour
    {
    [SerializeField]
    private GameObject[] monsterReference;

    private GameObject spawnedMonster;

    [SerializeField]
    private Transform leftPos, rightPos;

    private int randomIndex;
    private int randomSide;


    // Start is called before the first frame update
    void Start()
    {
    StartCoroutine(SpawnMonsters());
    }//end

    //coroutine
    IEnumerator SpawnMonsters()
    {
    while (true)
    {
    yield return new WaitForSeconds(Random.Range(1, 5));

    randomIndex = Random.Range(0, monsterReference.Length);
    randomSide = Random.Range(0, 2);

    spawnedMonster = Instantiate(monsterReference[randomIndex]);

    //left
    if (randomSide == 0)
    {
    spawnedMonster.transform.position = leftPos.position;
    spawnedMonster.GetComponent<MonsterMouvement>().speed = 8;
    }
    else//right side
    {
    spawnedMonster.transform.position = rightPos.position;
    spawnedMonster.GetComponent<MonsterMouvement>().speed = -8;
    spawnedMonster.transform.localScale = new Vector3(-1f, 1f, 1f);
    }
    }//end

    }//end

    }//class
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Hm, that is odd... Select them in the hierarchy and press F in the scene to focus. That will show them. Pull back and see where the camera is, make sure it's pointed where you think, etc.... try replace them with a Cube... check their scales, etc.
     
  3. coquelicotqc

    coquelicotqc

    Joined:
    Aug 24, 2021
    Posts:
    3
    I replaced them with cubes, and I still don't see them in the game view. Also, the camera is following the player. I can see the cubes in game view when they are the original prefabs. Thank you for helping me.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Then you've found a smoking gun. We know that cubes work fine and camera's work fine. Don't even consider ANYTHING else until you have a cube rendering.
     
  5. coquelicotqc

    coquelicotqc

    Joined:
    Aug 24, 2021
    Posts:
    3
    Ok
     
  6. banga10

    banga10

    Joined:
    Feb 13, 2021
    Posts:
    5
    i need help as i have the same problem
     
  7. banga10

    banga10

    Joined:
    Feb 13, 2021
    Posts:
    5
    if your game is 2d i found the soloution. check the z corordinates of your spawner and set it to 0
     
  8. zeyad-shaban

    zeyad-shaban

    Joined:
    Jul 10, 2022
    Posts:
    1
    I was just following the same tutorial actually and came here, i miss read banga comment and thought he was saying (set z scale to 1) when i checked my code i had my scale as following
    spawnedMonster.transform.localScale = new Vector3(multiplier, 0, 0);

    Don't worry about multiplier, it's just a variable for either -1 or 1, something i made to make my code simpler, anyways if you accidently made the scale for those two at 0 then your character is 0 pixel tall aka invisible, make sure they are at 1, did this fix the issue for you? if not here is my code, you can compare it to yours

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class MonsterSpawner : MonoBehaviour
    6. {
    7.     [SerializeField] GameObject[] monsterRef;
    8.     [SerializeField] Transform[] positions;
    9.  
    10.     GameObject spawnedMonster;
    11.  
    12.     int randomI;
    13.     int randomPos;
    14.     int multiplier;
    15.  
    16.     void Start()
    17.     {
    18.         StartCoroutine(SpawnMonsters());
    19.     }
    20.  
    21.     IEnumerator SpawnMonsters()
    22.     {
    23.         while (true)
    24.         {
    25.             yield return new WaitForSeconds(Random.Range(1, 3));
    26.             randomI = Random.Range(0, monsterRef.Length);
    27.             randomPos = Random.Range(0, 2);
    28.  
    29.             spawnedMonster = Instantiate(monsterRef[randomI]);
    30.             spawnedMonster.transform.position = positions[randomPos].position;
    31.  
    32.             if (randomPos == 0) { multiplier = 1; } else { multiplier = -1; }
    33.  
    34.             spawnedMonster.GetComponent<Monster>().speed = Random.Range(3, 10) * multiplier;
    35.             spawnedMonster.transform.localScale = new Vector3(multiplier, 1, 1);
    36.         }
    37.     }
    38. }
    39.  
     
  9. RushilMahadevu

    RushilMahadevu

    Joined:
    Jul 30, 2022
    Posts:
    1
    Thanks so much this helped alot
     
  10. Coco7_35

    Coco7_35

    Joined:
    Aug 23, 2022
    Posts:
    1
    Bonjours, moi j'ai un problème similaire pour un puissance 4: les pions spawn bien dans la scène et la hiérarchiemais pas dans le "Game". Les pions spawn à un "Transform".



    Voici mon code :

    Code (CSharp):
    1.  
    2. [ICODE][ICODE][/ICODE][/ICODE]
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using UnityEngine.UI;
    7.  
    8. public class ActionButton : MonoBehaviour
    9. {
    10.  
    11.      public Transform lachePoint1;
    12.      bool isYellow = true;
    13.      public GameObject yellowPiece;
    14.      public GameObject redPiece;
    15.  
    16.  
    17.     void Start()
    18.     {
    19.        
    20.     }
    21.  
    22.     void Update()
    23.     {
    24.        
    25.     }
    26.  
    27.     public void OnClick()
    28.     {
    29.         if(isYellow == true)
    30.         {
    31.             Instantiate(yellowPiece, lachePoint1.position, lachePoint1.rotation);
    32.             isYellow = false;
    33.         }
    34.         else
    35.         {
    36.          Instantiate(redPiece, lachePoint1.position, lachePoint1.rotation);
    37.          isYellow = true;
    38.         }
    39.     }
    40. }
    41.  
    42.  
    Merci pour vos réponses !
     

    Attached Files:

  11. Novekaru

    Novekaru

    Joined:
    Mar 22, 2022
    Posts:
    3
    Ive had the same problem as well, and the solution to my case was setting the Z-axis coordinate of the Spawner object to 0.

    I believe the reason why this happens is because the references rightPos and leftPos doesn't refer to the z coordinates of the Right and Left game objects, which are placed in the Spawner object. Thus the z coordinates of the Spawned monsters are automatically set to the z coordinate of the Spawner object which is the parent of the Right and Left.

    hope that helps
     
    Last edited: Oct 17, 2022