Different results from same code!

Hey guys!

I am working on a small rpg, last week I´ve made a inventory for the player:

Its a canvas with the render mode set to Overlay.

Today I started working on a inventory for containers , I am using the same code I used for the player inventory but the canvas element is´not placing in the correct place.

The canvas for the chest is a child of the “Chest” itself and the player inventory is the root (as you can see in the pic).
Could this be a problem?

As you can see in the pic the inventory is in the wrong place and with a bad scale :C

Thx for your time :smile: !

Any idea :stuck_out_tongue: ?

It’ s hard to tell without knowing how you create your canvases. Anchors work using a relative scale of [0, 1], so if you want to make UI tree A look the same as B you need to either:

  • Make sure the parent hierarchy is the same. I.e.: If “Chest” is a [0.25, 0.75] x [0.2, 0.8] panel/ subcanvas, you’ll need a like-sized parent for your player inventory.
  • Adjust the anchors and offsets for the new parent (in this case, the canvas root).

If you drag your chest’s Inventory child onto the root canvas you can see the values needed for there, though you might want to reposition your anchors and clearout any offsets, depending on your implementation. (If you need to do this, this utility script might save you some time (be sure to follow the link to the updated version).)

Hope this helped a bit. If not, please let us know exactly how you’re setting things up and such. =)

Thats the thing, how do I change the rect transform of the canvas itself:

I dont understand why I should move the canvas if its in Overlay mode :S

I´ve asked the same question in reddit but I can´t solve it:

https://www.reddit.com/r/Unity3D/comments/3flt2f/overlay_canvas_inside_other_game_object/

Should I just go for the easy solution , having 1 canvas in the hierarchy for each chest/container in the game…

Solved:
I made a empty gameobject and place it at 0,0,0 , then I nested inside it the canvas and the chest model itself and it works.