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
I swear I need to just bind this answer to a function key
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.
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.
Create a primitive object such as a cube in the hierarchy.
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.
Parent your imported object to the primitive.
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:
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.
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.
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 .