[SOLVED] 2D positioning prefab with multi-children

Hi,

I’m currently trying to create an game based on infinity plateform ascension. To do it, I use prefabs with multi-children.
On each of these prefabs, i placed 2 points (Top/Bottom).
I want that the bottom of the next prefab to be on the top of the previous one.

I thaught i could use the prefab center to calculate the right position.
But when i Instantiate it, it doesn’t fit. In fact, i understood that the transform.position of the prefab is not the middle of the prefab. ( Like on this picture )

Is there a way to set the prefabs transform position at the right place ?
Or have you got any better idea to perform this ?

Thanks,
Have a nice day !

2238212--149269--Sans titre 2.jpg

Did you select only the parent object, or did you select its children, too? The translation widget should be exactly where transform.position is.

Hi, thanks for answer,

Yes, i selected everything. Look these pictures. According to the selections tools. They all give me the center of the prefab. Which is actually nothing.
The last tool on the right shows me the real prefab transform.position because when i move the position in C#, this point is taken as transform.position.

I found some kind of stupid fix :

  • create an empty GameObject
  • keep its position in mind
  • selected all children of the prefab and move them to the empty gameobject position
  • attach them to this empty gameobject.
  • It’s the new prefab with the good transform.position

Any idea of why it’s not automatic ?

Anyway i found the solution, quite simple. Don’t know why i was stucked for one day. I just had to calculate the distance between the prefab transform.position and my bottom point and substract it to prefab transform.position.


You should have selected only the parent.

Glad you found the solution for your positioning problem :slight_smile:

Sorry, i misunderstood, i had selected only the parent. ( proof : if i had selected children the tool on the right would show a box)

Thanks, for support, seems that you’re always the first on topics :wink:

Hmm, but if you had selected the parent only, then it would be quite odd if the translation widget wouldn’t be at the same position transform.position gave you.

Yes, but for a moment I was sure that i would need the center of the prefab