I am working on a 3d puzzle game. I would like to make use of the device independent resolution features of the new UI. Can I place my 3d pieces in one of the new UI containers such as the Canvas or Panel? Is this possible? Would that take care of resizing the 3d stuff for different resolutions so I don’t have to bother adjusting my perspective camera’s position/fov for different sizes.
Thanks!!! I did try it out. I had to scale it at least 200 times to fit the outer Tile. Having to scale defeats the purpose of using the UI as a container. I was hoping to use the containers full stretch anchor to auto-size the child cube. The only reason I was trying this out was that when you right click on a UI element like a Panel etc there is a option to add 3d objects. I guess if this is not possible then they should remove that option from the menu.
If you got Unity Pro you can alternatively render your object with a separate camera into a RenderTexture, then display that in your UI with a RawImage component.
Hi you’re right i’d like to see how to create this possibility as well where the cube’s vectors will correspond to the rect transform’s width and height. Hopefully someone can teach us that
It would seem that they would need a 3d container transform to anchor in the z direction too. Which is why I am surprised they gave an option to add 3d objects to the UI (in the menu) which is 2d with the ability to be positioned in 3d.
It’s not going to happen automatically, the anchors are only really functional for RectTransforms. While you can attach a mesh renderer to a RectTransform, it’s not actually a Rect and won’t scale with one.
You could maybe write some clever code that scales the vertices of the mesh based on the RectTransform, but I wouldn’t recommend it. There’s just better ways of going about things.
Finally got around to working on the game again. I followed the advice above to Render to Texture. Works like a charm!! Don’t have to bother with camera positioning, World Space etc. Render to Texture to a RawImage within a Panel. Now you can anchor the panel to the canvas. You can also anchor the Raw Image to the Panel. You don’t have to bother about resizing/coding for different resolutions. The anchoring takes care of it all. There is an example of RenderTexture in the new UI demo in the asset store (free).
syed, when it came to rendering the model to a texture, did you manually place it so that it fit withing your camera’s view or did you find an algorithm to automatically find the ideal scale?
That is a minor issue I was having now and I think I resolved it. So my secondary camera renders the object to texture and it gets rendered onto the panel. However, the camera not only captures the object but there is some empty space of the scene view around it which gets rendered too. I could play around with the camera settings in the editor to show only the object, but if the resolution changes then again you get the empty space around the object. I tried putting the object in its own layer and the camera in the same layer with the same culling mask. I then set the clear flags to Solid color. Now I don’t see the empty space any more, no matter what resolution. This works but is there a better way of doing this - I mean focusing the camera to focus only on the gameobject and not the scene behind it, regardless of resolution? If somebody responds here that is fine, otherwise I will open a separate thread for it.