- Home /
[4.6 - UI] How to add 3d objects as canvas child?
Hi,
I want to have a 3d object as any other in my User Interface (I am using the new UI system, 4.6). It has to be a child of a rect transform object. If I add a basic cube as a child of the canvas it does not render (but it does in the inspector). Does anybody know any solutions for this?
I have done it with a RenderTexture. But this only works with unity pro on mobile.
When you set you Canvas Render$$anonymous$$ode to ScreenSpaceCamera or WorldSpace, your camera will render your 3d object (Depending on which layers it renders and in which layer your 3d object is ofcours). The way it currently works I believe is that 3D objects are placed relative to the pivot position of the parent. Which does allow you to control the position reasonably well, I assume there are also ways to control the scale so that it fits in screen % etc. But I haven't found that yet.
Answer by Lardalot · Dec 06, 2014 at 01:55 PM
Set your Canvas type to screen space camera. Set the scenes main camera on the canvas. You might need to tweak clip distances or canvas plane distances to make sure things are in view.
Answer by Mmmpies · Dec 03, 2014 at 09:48 PM
If using the free version, then you can't use RenderTexture but you can setup a separate camera that you can enable when in the menu. As long as the depth of the 3d objects is closer than the background for the GUI you should be OK.
This is a "very" basic setup I've got:
The canvas background and X button are the new GUI and the swords are 3D rotating objects.
Put the camera under the terrain facing in a direction it's not going to render anything else.
Set Clear Flags to Depth only. Create a layer for your 3D objects and set the Culling Mask to that layer. Projection should really be orthographic but it's not essential so if you want a certain look then that's OK.
These are the settings on the camera I use:
I did have a link for a full tutorial on this with the old GUI but can't find it. It still work with the new GUI.
Basically create the camera, make sure it only displays stuff in the layer for the 3dGUI camera and then set a blank game object close enough to the camera to display in front of the GUI canvas.
Create your first 3D object at the blank game object and whatever x,y,z increase so it then moves the next item along the axis to the right.
I'll try and find the tutorial but it's getting pretty late where I am so it might/will not be tonight!
PS Can't really do it on "free" as a rect transform but with a bit of imagination you can place it in the same area, just rendered by the additional camera. You just need to experiment with scrolling the uGUI at the same time as you scroll the 3dGUI camera. Oh and be careful with those different aspect ratios Eugene!
PPS I'm guessing most people are too young to get the Pink Floyd reference, in fact I guess most are too young to get PS and PPS, or at least not British.
Answer by sysmaya · Aug 08, 2016 at 03:59 PM
Two cameras. One Main Camera. Two for GUI Menu.
https://xinyustudio.wordpress.com/2013/11/05/unity3d-make-3d-objects-over-gui-surface/
Answer by christougher · Apr 16, 2017 at 07:21 PM
I know this is old, but here is a great asset to help align mesh objects on the screen.
https://www.assetstore.unity3d.com/en/#!/content/75607
I'm not the author, it's free, is super easy to use, and if you want to have objects overlay the canvas you can use screen space camera.
Your answer
