- Home /
Game Object visible in Scene mode but not visible in Game mode.
Right after I applied Object pooling for the obstacles and made the obstacles to a Prefab it's no longer showing in Game mode but it's visible in Scene mode.
Any help would be appreciated.
Answer by Legend_Bacon · Oct 15, 2018 at 01:37 PM
Hello there,
My first guess is that they get instantiated behind the background. Once instantiated, try selecting them in the scene and change their Z values.
Another cause could be Layers. If you've grouped your enemies/obstacles under a specific layer, make sure your camera is rendering them (Camera -> Culling Mask).
Other than that, I think you could try giving a little more info if you want more answers. Like your instantiation/pooling code, your setup in the scene hierarchy, etc...
I hope that helps!
Cheers,
~LegendBacon
I tried checking those. $$anonymous$$y initial prefab's z value is 200. And the prefab is clearly visible in game mode but when I Instantiate it it's not visible. And according to the ordering layer, obstacles and character are assigned to foreground making it visible. I can share the code if you'd like.
Please do, then we can make sure nothing's wrong there.
On another note, do they really have a Z value of 200? This sounds silly, but since all I see here is 2D, could it be that the obstacles actually spawn behind the camera (out of its frustum) ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObstaclePool : $$anonymous$$onoBehaviour {
public int hurdlePoolSize = 5;
public float spawnRate = 4f;
public GameObject columnPrefab;
public float column$$anonymous$$in = -1f;
public float column$$anonymous$$ax = 3.5f;
private GameObject[] hurdle;
private Vector2 hurdlePoolPosition = new Vector2(0, 0);
private float timeSinceLastSpawned;
public float spawnXPosition = 20f
private int currentColumn = 0;
void Start () {
hurdle = new GameObject[hurdlePoolSize];
for (int i = 0; i < hurdlePoolSize; i++)
{
hurdle[i] = (GameObject)Instantiate(columnPrefab, hurdlePoolPosition,Quaternion.identity);
}
}
void Update () {
timeSinceLastSpawned += Time.deltaTime;
if (GameController.instance.gameOver == false && timeSinceLastSpawned >= spawnRate)
{
timeSinceLastSpawned = 0;
float spawnYPosition = Random.Range(column$$anonymous$$in, 0);
hurdle[currentColumn].transform.position = new Vector2 (spawnXPosition,spawnYPosition);
currentColumn++;
if(currentColumn >= hurdlePoolSize)
{
currentColumn = 0;
}
}
}
}
Answer by shaaafeee · Oct 16, 2018 at 12:49 PM
I found the solution. I played with the z axis, set the position to zero therefore it's working now. Thanks for the help . It was a silly mistake.
Ah, I did think that a Z of 200 was a little weird for a 2D game.
Glad I could help!
Your answer
Follow this Question
Related Questions
Making a 2D 16-bit game. 0 Answers
Help with 2D topdown combat 1 Answer
When should I use tilemap and game object? 1 Answer
2D Top down physics with ground (slippery floor...) 1 Answer
Problem With Pixel Art Pixel Size 2 Answers