Hi all, Do you know if it's possible to render a Renderer Texture inside UI Elements? I would use it to show the minimap of the game. Thank you
Sure, you can use an Image component for that. Code (CSharp): var renderTexture = new RenderTexture(160, 160, 24, RenderTextureFormat.ARGB32); var item = new Image(); item.image = renderTexture; m_MainCamera.targetTexture = renderTexture;
Hi stan-osipov, If I am not mistaken the Image class can't be used with the new UI Elements, right? Or, can you please provide some more guidance on how to add it in the UI Builder? Thank you
The Image component is not present in the builder Library at the moment. But you can use this workaround: Add the VisualElement from the library Save uxml file Open uxml file and change manually VisualElement to Image Switch back to the builder
Yes, it works! Another question: in order to do a round minimap we would have used a mask image with canvas. Is there any workaround / best practice to cut the texture using a mask image? Thank you
To create a round mask, simply set overflow to hidden and set border radius. Alternately, an SVG can be assigned to the background. In any case, note that atm we only support one level of masking. In the future we will support more but there will be an additional performance cost when using nested masking.
Hi! The hidden overflow + border radius kinda works, but for big images (300px +) the radius edges are visible, and the final result looks more like a polygon than a circle: I tried the SVG way, using a sample SVG like this: Code (xml): <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <circle cx="100" cy="100" r="100" /> </svg> I installed the "Vector Graphics" package (latest preview) and selected the "UIElements Vector Image" format: Then I assigned it using C#, as UIBuilder doesn't seem to support VectorImage drag&drop yet, like this: Code (CSharp): var mapTextureImage = this.FullMapPanel.visualTree.Q<Image>(name: "map-texture"); mapTextureImage.image = this.FullMapTexture; // Render texture mapTextureImage.style.backgroundImage = new StyleBackground(this.FullMapMask); // Mask vector image And it worked! Thank you all for the kind support. PS: Make sure Overflow is set to Hidden even if using SVG, or else it won't work.