Hi, I’m having a bit of a problem with something I have done a “million” times before.
I’m instantiating a prefab and print out it’s position to the log.
For some strange reason all of the created prefabs is placed at 0,0,0.
This is driving me nuts! I have used Instantiate without any problems in the past.
Here’s the code:
for( x = 0; x < MAP_W; x++ )
{
for( y = 0; y < MAP_H; y++ )
{
var tile = getTile(x,y);
var pos = Vector3( x*2,0,y*2 );
if( tile == 0 )
{
var obj:Transform = Instantiate( floor, pos, Quaternion.identity );
obj.parent = transform; // Commenting out this line does not fix the problem.
Debug.Log( "prefab created at " + obj.position.x + ","+ obj.position.z );
}
}
}
I have also tried to place them using Translate but to no effect.
Would be very grateful if someone coud spot the error.
I’m using the latest Unity and Blender 3D. I’m importing my models using the script that allows Unity to correctly load the Blender files autiomatically.
It looks like this is part of the problem. If I use a Unity created Box as a prefab it is placed correctly but my Blender models is all placed at 0,0,0
I know it’s late for this thread, and probably unrelated, but I have been stumped a few times before by accidentally importing Blender files with animations included. Then, despite my editor changes, they would ‘reset’ their position when the game ran. Maybe this will help some other readers even though I guess this particular issue is resolved now!
The fix for the animations issue is to (A) understand animations imported from Blender – which I don’t yet – or (B) select the fbx importer or .blend file in the Project window and set it to not import animations with the FBX. This usually works for me as I do not use animations in my current projects.