#Objects on showing up in game view despite being instantiated

1 messages · Page 1 of 1 (latest)

torn matrix
#

I have a Unity Universal 2D project set up and this script to create a grid of tiles:

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class GridManager : MonoBehaviour
{
    [SerializeField] private int gridWidth, gridHeight;
    [SerializeField] private T tile;
    [SerializeField] private Transform camera;
        
    // Start is called before the first frame update
    void Start()
    {
        for (int i = 0; i < gridWidth; i++)
        {
            for (int j = 0; j < gridHeight; j++)
            {
                var newTile = Instantiate(tile, new Vector3(i, j), Quaternion.identity);
                newTile.name = $"Tile {i} {j}";

                bool offset = (i % 2 == 0 && j % 2 != 0) | (i % 2 != 0 && j % 2 == 0);
                newTile.Init(offset);
            }
        }

        camera.transform.position = new Vector3((float)gridWidth / 2 - 0.5f, (float)gridHeight / 2 - 0.5f, -10f);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

and it does work, as I can see the objects in the hierarchy being created
but I don't actually see my objects in the game view (the sprite renderer has a white colour), so I'm a bit confused about why

still dawnBOT
torn matrix
#

i also tried changing the sprite colour during game view but it still doesnt show up

carmine bane
#

Maybe the position your providing is not placing it where you expect, what values do the inspector gives when you select one of those instantiated objects? You can also hit "F" on any selected object and the Scene view will jump to the position of that object - if they ARE where they should be, then it could either be a z-depth issue, a layering/camera rendering issue, or a material issue/something with your Renderer component on them - also is the red a background color of your camera or from another object in your scene? If the latter its possible its infront of your tiles

torn matrix
#

red is the background colour

#

i checked the position already its all within the view port

#

i thought it was something with the sorting layers but i dont have the objects on any different layers so idk

long needle
#

show the inspector of the sprite

torn matrix
long needle
#

can you show one tile being displayed

#

not instantiated

#

@torn matrix

torn matrix
#

wdym

#

the tile object is a prefab i dont have any tiles in the scene

#

all of them are instantiated

long needle
#

drag it into the scene manually @torn matrix

#

show your camera inspector too

carmine bane
# torn matrix

In that screenshot, it looks like your color alpha is zero on your Renderer?

open stirrup
#

I can see it from here

#

The color of the tile has an alpha of 0