- Home /
How do I fix this error code: BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(System.Collections.Generic.List., UnityEngine.Vector3, UnityEngine.Quaternion)' was found.
I am fairly new at unity and coding in general. I have a script I have been putting together and it keeps having this error:
BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(System.Collections.Generic.List., UnityEngine.Vector3, UnityEngine.Quaternion)' was found.
Here is my script:
The error is on line 39. I have tried to find an answer everywhere, but with no success. Any help would be appreciated. :)
Answer by tanoshimi · Feb 28, 2015 at 09:17 AM
The error is exactly what it says on the tin.
If you go to the manual, you can see the different versions of every method available in Unity. Looking at the Instantiate page, it lists two versions at the top of the page:
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);
public static Object Instantiate(Object original);
On Line 39, you're calling:
Instantiate (blocksList, spawnPosition, spawnRotation);
blocksList is a List (you declare it as such on Line 25). spawnPosition is a Vector3. And spawnRotation is a Quaternion. So which of the two versions of the Instantiate method fit that set of parameters? Neither. That's why Unity is telling you "No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(System.Collections.Generic.List., UnityEngine.Vector3, UnityEngine.Quaternion)' was found"
Considering the context of the rest of your code, I imagine you wanted to instantiate a single element from blocksList. i.e. Line 39 should read:
Instantiate(blocksList[i], spawnPosition, spawnRotation);
(p.s. in the future please post code as a codeblock, not a screenshot)
Thanks for the response to my question. (As you can tell I am not very experienced!) I did as you suggested and put blockList[i], but it gave me this error ins$$anonymous$$d of instantiating the GameObject:
ArgumentOutOfRangeException: Argument is out of range. Parameter name: index
Also, yes. The goal of my script is to instantiate a random GameObject from a list to a random position.
Here is a non-screen shot of my code. (Sorry, I did not know about the "codeblock" feature.)
import System.Collections.Generic;
var blocks : GameObject [];
var blocksList : List.< GameObject >;
var spawnValues : Vector3;
var blockCount : int;
var spawnWait : float;
var startWait : float;
var waveWait : float;
function PopulateBricksList()
{
// declare a new list
blocksList = new List.< GameObject >();
// get the length of the built-in array
var totalBlocks : int = blocks.Length;
// add each brick to the brickList
for ( var i : int = 0; i < totalBlocks; i ++ )
{
blocksList.Add( blocks[i] );
}
}
function Start () {
SpawnWaves ();
}
function SpawnWaves () {
yield WaitForSeconds (startWait);
while (true)
{
for ( var i : int= 0; i < blockCount; i++)
{
var spawnPosition : Vector3= new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
var spawnRotation : Quaternion= Quaternion.identity;
Instantiate (blocksList[i], spawnPosition, spawnRotation);
yield WaitForSeconds (spawnWait);
}
yield WaitForSeconds (waveWait);
}
}
Never $$anonymous$$d, your answer worked. Thanks so much for all your help!
Answer by hexagonius · Feb 28, 2015 at 09:14 AM
blocksList is of type List. You need to fetch one element of that list.
Your answer
Follow this Question
Related Questions
Simultaneous Null Reference Exception and expected value 1 Answer
Object reference not set to an instance of an object 1 Answer
Instantiating Rigidbodies on PhotonNetwork? Am I doing it wrong? 1 Answer
Keep Instantiated GameObject while exit gamemode in unity 0 Answers
Instantiating an object as a trigger does not send the trigger event 3 Answers