UI prefab centers all children

I have some gameobjects which have a canvas and their children. I set up the position and everything and then drag them to my Resources folder to make a prefab. If I do edits I make sure everything is applied, but no matter what I do, when I Instantiate the gameobject the canvas and all it’s UI elements are placed at the center of the object. For example, I created a healthbar, placed it at the bottom of the object (2D game) and then created the prefab. I then Instantiate at runtime and boom… healthbar is at the center of the sprite. I can manually move them in a script, but that doesn’t seem like intended behaviour, as complex UIs would just get ridiculous.

There’s not enough information that I can tell if this is intended behavior or you’re hitting a bug. Is it the instantiated object itself that changes position, or one of its children? What code do you use to instantiate it with, etc.? We’re not aware of any issues like this, so if you think you’ve found a bug, make a bug report.

Ok, so I have a player sprite with a canvas as a child, and an panel and image as a child of the canvas. I use the panel and image to make a healthbar. While the player is in the hierarchy I position the canvas and images where I want them and save the prefab. Then I do a normal Instantate(myGameObject, position, rotation) call, but when the player shows up the bar and canvas are all centered on the object.

In typing this explanation I had a thought. The canvas adjusts itself automatically, correct? I’m going to go test this but I’m realizing I had the canvas the exact same size as the image, and just positioned the canvas where I wanted. I’m thinking I need to have the canvas centered on the player and then place the image where I want with correct anchors…

It’s still not really clear to me, but I hope you find a solution. You’ve set the Canvas to be World Space, right?

My thought wasn’t the fix, so here’s a couple screenshots to explain what’s happening.

Here’s how I set up the healthbar using UI.

You can see I have everything uniform and anchored correctly (to my knowledge). But here’s what happens when I do Player = (GameObject)Instantiate(PlayerPrefab, PlayerSpawnPosition, Quaternion.identity);

All the child object of the canvas parented to the prefab move to the middle of the player object. I thought it was just the canvas moving at first, because I had the canvas be the same size as the healthbar. However in this image you can see I increased the size of the canvas and applied anchors, which still exist but are now being ignored.

Also, I downloaded Unity 4.6 when it was still in beta. Is there a patch to update to the release build, or do I need to redownload completely? A few minutes ago I thought maybe the issue is resolved in release. I can try that as well so I don’t file an obsolete bug.

I installed the release version of 4.6 and the issue has resolved itself. False alarm. Too bad I wasted so much time messing with that…