Arrows not instantiating at correct position?

Hi!

I have followed the instructions on this video properly as far as I can tell, but my arrows are spawning away from the environment, way up in the air.

Any idea what could be causing this please?

Is it possible that the components of the Arrow prefab are set to positional values other than 0?

No they’re all at 0. Had reset them, but double reset it just now to be sure.

Update

I tried resetting the transform component of the individual parts, and it seems to be (better?). They’re spawning at the field, albeit the rotation is not coming out right (aiming to the side, regardless of how I turn the rotation in the prefab edirot), and the theyre still spawning a little bit higher than my camera. Screenshot attached for reference.

But I mean even if I “fix” it by constantly doing slight adjustments to the individual components height and rotation, I wouldn’t really be satisfied with that. The position and rotation should come out correctly independent of the preset position and rotation due to the script, no?

The script is setting the prefab’s top level position and rotation, but it doesn’t affect the children of the prefab directly. The position, rotation and scale of the arrow’s shaft and head are set in relation to their parent.

To try to explain it better, say you have the arrowhead set with a y position of 10. When you instantiate the arrow prefab, the arrowhead will be ten units more on the y-axis than the position given to its parent prefab on instantiation. So if you instantiate the arrow in the world position of 5, 5, 5 the arrowhead will be at 5, 15, 5.

The same is true for the rotation, if the arrowhead is rotated 90 degrees then it will always be rotated by that amount relative to the rotation of the full prefab.

Really appreciate the explanation. Managed to play around and get it fixed and semi-understand what’s going on! :slight_smile:

On a sidenote, maybe it’s because I’m new to all this but this just seems like a weird constraint to me? Like, moving the Arrow parent (consisting of shaft and tip) higher on the Z axis, the individual parts would still be marked in their original position (which was what your point was, I believe). But what if I had something more complicated than an arrow made of 2 shapes? If I started it in the wrong rotation or position, I’d have to move every part individually? Or am I missing something?

1 Like

I’m glad that helped!

The highest level position and rotation values aren’t stored when a game object is turned into a prefab in order to avoid that sort of problem. Whether the base arrow was originally created at a position of 0,0,0 or 500,20,7 the prefab that results when you drag the game object from the scene will have 0 for all position and rotation values. So, yes, if you start off with the wrong rotation or position for a childed object and build everything based on that child’s position/rotation it would cause a lot of problems to fix later. Hopefully by knowing this now you won’t make that mistake. :slight_smile:

This is something that tripped me up when I first learned about prefabs, too! I had a simple character with a movement script and I had no idea why it was facing sideways when I moved it around.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms