- Home /
blender object instantiating in the wrong place
The Problem: I am trying to get an arrow imported from Blender to instantiate from a Launch object at a certain location in the scene. Instead, the arrow instantiates at Unity's 0,0,0 origin.
When I remove the arrow and instead instantiate from the Launch a rectangle I created in Unity, there is no problem: the rectangle instantiates exactly where it is supposed to.
What I've tried so far: I reset the arrow's center, location and rotation to zero in Blender before importing.
Any idea what could be making the object do this?
The code (attached to the Launch object):
#pragma strict
var projectile : GameObject;
function Update ()
{
if(Input.GetButtonDown ("Fire1"))
{
Instantiate(projectile, transform.position, transform.rotation);
}
//When the user presses the "fire1" button, the attached object, i.e. projectile, is instantiated.
}enter code here
After making sure the arrow's center, location, and rotation is zero, try saving and importing the model with another name. I've tried that Unity remembered the old version, no matter how many times I updated it.
Just reset center, location and rotation in Blender and re-imported. Problem's still there.
I've also noticed that the arrow won't move unless I click twice on the scene. Whereas, the unity-created missile begins moving immediately upon instantiation, just as the script requires.
This is really frustrating.
you have to instantiate a prefab.
I know it sounds silly but a imported object is not a gameobject and only game objects can be instantiated how you want.
What that means is you need to drag an arrow into your scene and then add all the components you want like a rigidbody and stuff and then drag it BAC$$anonymous$$ from hierarchy to project and then instantiate that.
Yes, I have done all of that. I should have said "Blender prefab" rather than "Blender object" instantiating at the wrong place.
you thought you did, you didn't, drag and drop the prefab over the projectile variable again.
I just reproduced it right now, if i drag the raw import with the little piece of paper and default take attached and import settings and all that, and i instantiate that, it only spawns at 0,0,0.
If i take an actual prefab i made of that i get it to spawn right.
Just to be clear, the thing with the import settings THAT IS NOT a prefab. I know it has a little box and it kinda looks and behaves like one. Its not.
SO go back and look at the thing you dragged into the projectile variable. When you click on it does it have a transform? If no your using the wrong thing, if yes drag and drop again to make sure.
Answer by Loius · Nov 10, 2012 at 09:50 PM
I swear I need to just bind this answer to a function key :P
Animations contain positional data. If you want to move an animated object, you must either refrain from animating position in the animation software, or you must make the animated object a child of a positioning object, or you must remove the animation component.
^ That's also why you two in the comments are having different results. Sparkz's prefab has no animation attached to it.
Haha, wow. Yes, that fixed it. Thank you very, very much. I have spent the past two days and hours of what should have been sleep trying to figure out what was wrong with the arrow. And the most laughable part of this is that I didn't need an animation on the object anyway. It came loaded I think on the object I modified in Blender. Because I didn't add the animation component/alter it in any way, it just didn't occur to me that it could be the problem.
Answer by ToddToddTodd · Sep 04, 2014 at 07:02 AM
I had trouble with using animated objects made with Blender. Not rigged character animations, but objects with location and rotation animated. The object would go to the wrong place during play no matter where I positioned it with play off. I found that parenting the object ( as Louis says above) or animating it in Blender with a rig could fix the problem.
Parenting the object to an empty worked, but I had trouble when I tried to make a prefab and instantiate it. When I did there was something wrong. A script node didn’t remember what was assigned to it or something.(can't remember for sure). However, I got it to work by making a sort of false empty.
Here's what I did. 1. Create a primitive object such as a cube in the hierarchy. 2. Then turn off or remove the collider and mesh renderer for the primitive. Now you have an object that can work as an empty but is not really an empty.
3. Parent your imported object to the primitive. 4. Then you can bring the primitive back to the project window to make it a prefab.
I don't know if I needed to do this, but I was having trouble otherwise.
Second Method Another solution is to rig and animate the object in Blender rather than using simple location and rotation animations. (This won’t work for simulations of course. )
Steps: 1. Create one armature bone in Blender and parent the object to it. All vertices will attach to the single bone, so you won’t get any deformations. 2. The location and rotation of the object can then be changed by animating the location and rotation of the bone in “pose mode” just as you would with a character rig.
Answer by Zeta-26 · Mar 15, 2021 at 11:50 PM
Okay i dont know if your issue is the same than mine, but i has an issue about instanciate object in unity scene, the object was not instanciate at the good position, i try with a primitive 3d object (sphere) and in this case everything work well so i know the issue was about the .obj (or.fbx) file even if i make it become a prefab after. i was trying to apply solutions i see on internet about parent's object situation but no any resolve my issue. In my case the solution was to reset the object's position in the blender files with blender software and nothing with unity. Then reexport the file and reimport in unity, this time everything was working well. Maybe this can help some people in same situation..
ps: I know the post is very old but it seem to always be reference in google for people search with some keywords so why not .