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. Dismiss Notice

Argument Exeption : The prefab you want to instantiate is null with instantiate

Discussion in 'Scripting' started by Bioshok2, May 20, 2014.

  1. Bioshok2

    Bioshok2

    Joined:
    Apr 14, 2014
    Posts:
    60
    Hello everyone,
    I want to instantiate multiple instances of the prefab flame in the game in different places.
    but problem: argument exeption: the prefab you want to instantiate is null with this code:
    please help me.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Particules : MonoBehaviour {
    6.  
    7.  
    8.  
    9.     static byte nombre4 = 135;
    10.     byte a=0;
    11.     GameObject[]liste1 = new GameObject[nombre4];
    12.     float distance = 70f;
    13.     public Transform prefab ;
    14.  
    15.  
    16.  
    17.     // Use this for initialization
    18.     void Start () {
    19.         for (int i=0, x =0,y=0,z=0 ; i < nombre4; i ++) {
    20.             liste1 [a] = Instantiate (Resources.Load("Flame"), new Vector3 (x * distance, y * distance, z * distance), Quaternion.identity)as GameObject;
    21.             x+=5;
    22.             y+=5;
    23.             z+=5;
    24.             a++;
    25.         }
    26.            
    27.     }
    28.    
    29.     // Update is called once per frame
    30.     void Update () {
    31.    
    32.     }
    33. }
    34.  
    Thank you and good day.
    Cordially.
     
  2. MysteriX

    MysteriX

    Joined:
    Apr 8, 2014
    Posts:
    54
    It simply means that you have no Prefab called "Flame" in your resources folder?
     
  3. Bioshok2

    Bioshok2

    Joined:
    Apr 14, 2014
    Posts:
    60
    Hello MysteriX,
    I use the prefab Flame , default resource of Unity packages
    Standart assets => particles => fire => "Flame"
     
  4. MysteriX

    MysteriX

    Joined:
    Apr 8, 2014
    Posts:
    54
    I do not have unity here in the moment. But I think you have to copy it to an resources folder. This folder can be where ever you want.