Drawing polygons to the HUD

I’m looking to create a HUD, but in this, I would like to draw a non-rectangular polygon to the screen (which will change size and shape depending on the game state). It seems, however, that the HUD does not supply a “DrawPolygon” function (providing only the capability to draw textured rectangles). It seems, however, that the Canvas class does have this function, but I’m having trouble working out how to use it. My understanding was that it would require the creation of a CanvasRenderTarget, which would then be updated (to call the update event) and rendered to using the Canvas drawing tools. Then, I could draw the render target to the screen instead.

That was how I understood it, but try as I might, I couldn’t get the CanvasRenderTarget update event to run, so the RenderTarget was never drawn to. Can anyone help me work out how to do this? There seems to be precious little documentation on it.

P.S. I’ve been doing this entire thing using Blueprints. There is some suggestion that it requires C++, and while that’s not necessarily a problem, I don’t see why, as it seems to access the same set of functions.

Hi,
I am not sure about it, but I think Canvas does not have such function - to create 3D objects - Static Meshes for the HUD.
If you look at that “swing ninja” game you can see an easy way to use Static Mesh as a simple HUD,
the only difference you’d have to make, is set those Static Meshes locations each Tick, so that they would follow your camera.

No, it does. There’s a function called “DrawPolygon”, which is designed for doing just this. I’m not talking about drawing 3D objects, but 2D vector polygons, for example, drawing a triangle in the corner of the screen. It’s nothing to do with static meshes.

You’re right, well I tried creating blueprint from Render Target 2D, and yes in there you can use DrawPolygon function, however it still needs to be included in the HUD somehow, and I couldn’t figure out how yet and don’t have time right now.
You also need to think about touch if you’re making a button.
Creating a HUD with Static Meshes doesn’t seem like a bad idea to me thou,
considering you can make any custom shape you want, from a triangle to rotating 3D objects etc, and make stretch and squash effects and things like that.
Good Luck

Well yes, that’s exactly the problem I had. I’m not making a button, just a display. Also, static meshes have their own issues. Sure, they’d work, but they can produce problems with depth, and are more performance-hungry than polygons drawn in screen space, especially since, as I said, I need to change its shape during execution.

Okay, I’ve made some headway with this. Instead of drawing polygons directly to the HUD, I’ve made a material that draws what I want based on a floating point parameter. The trouble in, my MaterialCollection doesn’t seem to be working. I’ve made a Material Collection with a scalar parameter called “Amount”. I’ve then used a node in the shader that collects this parameter. I’m then updating the parameter from a different blueprint. I’ve done some debugging, and the parameter is definitely being updated to the correct value, but for some reason, the material is being drawn as though the parameter is constantly 0. Would there be any reason for this?

Right. I fixed this by using a material instance, and now the rendering works as expected. I’m not going to close the question though, because this is a rather round-about solution, and I’d like to know if there’s a neater one available.