Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Instantiated object, missing sprite, wrong layer.

Discussion in 'Scripting' started by Temp10101, Mar 31, 2015.

Thread Status:
Not open for further replies.
  1. Temp10101

    Temp10101

    Joined:
    Feb 11, 2015
    Posts:
    54
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class RandomMinorities : MonoBehaviour {
    5.     public GameObject speedBoost;
    6.     public GameObject moneyCoin;
    7.  
    8.     void Awake() {
    9.         GameObject.Instantiate(speedBoost, new Vector2(0, 0), Quaternion.identity);
    10.     }
    11. }
    12.  
    This very basic script doesn't work as it should. I placed Prefab as speedBoost. Prefab has image in it, it's a retro-coin downloaded from internet. But it only says "missing sprite", as soon as I point it, I need to put it on layer higher than 10. Prefab already has image, can't I make script inherit it? Also, how do I change layer of order of an object?

    So, as soon as I point it to image AGAIN and I set it on layer more than 10. Then it's visible.
     
    Last edited: Mar 31, 2015
  2. Temp10101

    Temp10101

    Joined:
    Feb 11, 2015
    Posts:
    54
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,999
    is the speedBoost prefab in the Project folder?
    If you drag it to scene from there, does it work?
     
  4. Temp10101

    Temp10101

    Joined:
    Feb 11, 2015
    Posts:
    54
    Yes, it is, both image and prefab are in folder Asset.

    As I mentioned, yes, if you re-point the image to the Instantiated object, and set layer to higher than a certain amount (it's around 10, then it's visible).
     
  5. XGlitchedLogicX

    XGlitchedLogicX

    Joined:
    Jul 30, 2021
    Posts:
    1
    2022 and this issue is still happening.
     
    Vickey_Soni likes this.
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,563
    We all know the date, unfortunately we don't know what issue you're referring to. Someone had a problem in 2015, it doesn't mean there's a bug in Unity.

    Talking about 2015, please don't necro posts, especially for unhelpful comments like this.
     
    Vickey_Soni likes this.
  7. Vickey_Soni

    Vickey_Soni

    Joined:
    Jun 9, 2022
    Posts:
    10
    I had the Similar "Issue", cause I tried changed order of layers multiple times (Even On Run Time). But found "Solution", Dumb me forgot that I had the Element in the child while I was just changing parent's Order.
     
Thread Status:
Not open for further replies.