- Home /
Error with instantiate after build
Hi, I was trying to add a 'fireball' attack to my wave game, and built the game after i got it working in the editor. When I ran the file I got a wierd error in my log file:
NullReferenceException
at (wrapper managed-to-native) UnityEngine.Object.Internal_InstantiateSingle_Injected(UnityEngine.Object,UnityEngine.Vector3&,UnityEngine.Quaternion&)
at UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, UnityEngine.Vector3 pos, UnityEngine.Quaternion rot) <0x1f249e69bb0 + 0x00062> in <3a69dc1755714a688e272fb29550dc99>:0
at UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) [0x00025] in C:\buildslave\unity\build\Runtime\Export\Scripting\UnityEngineObject.bindings.cs:202
at UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) [0x00009] in C:\buildslave\unity\build\Runtime\Export\Scripting\UnityEngineObject.bindings.cs:276
at Player.Update () [0x00207] in C:\Users\d.o22\Desktop\CS30 PROJECT DO\Assets\Scripts\Player Scripts\Player.cs:95
(Filename: C:/buildslave/unity/build/Runtime/Export/Scripting/UnityEngineObject.bindings.cs Line: 202)
Here is line 95 which it says has a problem:
GameObject FireballGO = Instantiate(FB, vfbsp, Quaternion.identity);
It works completely fine in the editor, but i get these errors only in build. I searched online and found about 2 others with a similar issue, but there were no answers to their problem. If you need more info to help let me know and ill try to provide. Thanks.
Answer by JasonBennett · Jan 08, 2020 at 08:45 PM
Hello @d-ostapa,
Could you tell me a bit more about the GameObject FB and the Vector3 vfbsp (I'm assuming that's a Vector3-- not sure of overloads for Instantiate() off the top of my head, could be a Transform that it's converting to Vector3)?
1. Are they referencing objects from the Inspector? 2. Or are they assigned earlier in code? 3. What platform are you building? (Guessing Windows, just want to be sure)
-Jason
Game object FB is the Fireball prefab. The vector 3 vfbsp is defined earler in my code:
void Update()
{
Vector3 vfbsp = FBSP.position;
FBSP is a transform from an empty gameobject thats a child to my player.
public Transform FBSP;
And yes i am building in windows.
Hmmmm... this is strange. It is obviously not finding the prefab object in your Assets at build time, but why?
I would check to see if you can instantiate a different (brand new) prefab that you drop into the FB bucket. Just use something simple like a sphere. If the new one instantiates ok, then there might be a problem with one of the .meta files pointing to the prefab in your Assets.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Creating a GameObject variable without instantiating it? 1 Answer
Instantiating a prefab and values 1 Answer
The object is not output. 0 Answers
Retain references to child gameobjects while duplicating objects 0 Answers