- Home /
Could someone help me with instantiate function? It's not working. Weird.
void generateEnimies() {
foreach(int i in Enumerable.Range(0, 10))
{
var clone = Instantiate(enime);
clone.SetActive(true);
clone.transform.position = new Vector3(0, 0, 0);
}
Debug.Log(e);
}
why doesn't it work if enime != null and function is definitely called (I checked) Edit: there are no errors, nothing is spawned, but the instantiated object exists(how?) if you call debug.log. There is no new game objects and nothing new in hierarchy. Enemy is enemy prefab that I want to instantiate.
What's the error message given?
Also, instantiate has multiple inputs, but I don't know what Enime refers to. if it refers to an object, you'd have to fill in the position and others too. There are a lot of ways to use instantiate, as clearly stated in the documentation. you might have to define everything you want first if you haven't done that, there's no way for the script to know what enime is. Also, quick little thing, enime is either anime or enemy.
What do you mean "it's not working"? Is the thing being spawned in the wrong place? Check the Hierarchy for something like GameObject (clone)
. If you see something with (clone), it means Instantiate
worked.
Answer by barry1251 · Mar 08 at 11:40 AM
And the simple pool is just basically instantiating these objects and putting them into a pool. MyLabCorp Patient Portal
Answer by grimreefer24601 · Mar 08 at 06:02 PM
It sounds to me like Instantiate is returning a null. If Instantiate fails for any reason it will produce a null value. It should throw an error message in the editor, but won't stop running necessarily. Have you stepped through the code in the debugger? I''d put a breakpoint at line 5 in your code; and see if the clone has any data of if it's null.
Function is returning a proper game object that should(theoretically) be displayed in hierarchy and be in the scene. I also checked the scene, and it is scene that I looked in while trying to find this weird gameobject @grimreefer24601
Your answer
Follow this Question
Related Questions
Gun Switching Error 1 Answer
Why does unity3D crash when starting this script in play mode? 1 Answer
when pressing play gameobject get deleted and the game breaks 0 Answers
Setting the parent of a transform which resides in a prefab error 1 Answer
[Closed]NullReferenceException on Object Instantiation onto game world 2 Answers