I have a script that changes anchor and pivot values of some entities inside a group and places them side by side.
The issue I have is that these items are placed wrong, as the pivot never changed (the anchor changes are respected instead).
If I select the parent in the editor, and I touch its position, then all the children get places correctly.
I tried to change and restore by code the position of the parent, but it doesn’t work.
It seems to be a bug. I can’t complete my code without resolving this issue.
Any hint will be much appreciated.
Open the “Pivot Issue” scene and hit play. You will see that the leftmost square is outside of the view by its half.
Select the parent in the editor, and change the position a bit. Suddenly all the squares go in the correct place.
I see what’s wrong. In your HorizontalAlignment script you are setting values of the pivot / anchors using pc.Vec3#copy. You need to assign the pivot / anchor vectors to the Element’s properties in order to take effect - it won’t work if you are changing their x,y,z values directly.
Yes it makes perfectly sense because pivot and anchor are properties.
I didn’t want to share the same vector with all the elements and I thought that copying the values would have been better than create many new vectors.
Strangely by setting the anchor the same way seemed to work and that confused me more.
Thank you for your great support!