Guys, it is possible to do someting like this in UE4 with blueprints?
Use beam particles, they are fast to render but bit hard to manage.
Or
Spline mesh actors, those are bit slower to render, but imo easier to draw lines, arcs and circles with them.
Also I am not sure if you can render them in 2d game.
I’ve made this before in blueprints, and I used spline mesh actors.
You will need, a custom HUD blueprint, a blueprint for spawning the spline (could go in your player either), a plane shaped mesh to use as collision, a spline blueprint, a player controller that has show mouse enabled, and a custom structure containing an array of vectors.
How I done this wasn’t very optimized, and would need more work to get it to looking good (it just uses draw line in the HUD for the visual). But I’ll briefly show the parts here.
Create the structure mentioned above, I called mine S_SplinePoints, it has an array of vectors called Coordinates.
Create a HUD blueprint. Add a variable of type S_SplinePoints, and make it an array. Now you have an array of an array of vectors, this will be used for drawing lines on the HUD to show the what the player has drawn. There would definitely be more efficient and visually better ways to do this.
Here is the HUD:
The values of SSplinePoints will be set from another actor later, it contains the coordinates of all points on the splines drawn by the user. This loops through them and projects them to screen space to draw the line.
This is the actor which spawns the line collision. When the use is holding right clicks and draws, a red line will show what they are drawing, when they release right click, that line will have collision generated for it.
Here is the input:
On right click, a spline is spawned, the User Spline object is simply a blueprint with a spline component. It is set as Drawing Spline, and an empty S_SplinePoint is added to the array in the HUD.
When right click is released, Custom Points is cleared (see below), and the collision is generated, I will show that function below.
Here’s the tick event for the actor. It adds points to the spline, and updates the HUD’s array.
It only does anything if Right Mouse is pressed. It traces from the cursor and sets that as trace location. IsEmptyArray is a custom macro to check if the array is empty, it’s sort of just a more verbose DoOnce, you don’t have to do it like that, but it works well.
The first point is always added, after that, it will only be added if the new point is a certain distance away from the last one added, here i have this distance at 20, the lower the distance the more points you will get. The DistanceIsGreater is a custom macro to check that. As points are added, the points of drawing spline created above are also set, and the points are set in the HUD. It gets the last element added (the most current spline), and sets that element with the current coordinates. (The spline points array shouldn’t be there at all) .
Here is the AddSplineCollision from above, the inputs are the loop index and the mesh you want. This mesh should be a rectangle shape, mine is 10x50x140cm. This mesh should have Use Complex Collision as Simple, in static mesh settings.
Make sure on the Add Spline Mesh Component, you have Visible unchecked. When it is setting the start and end points I am forcing the Y tangent to be negative, this is to prevent the spline mesh flipping to the wrong side, you’d have to play around with that because it would depend on your mesh and how everything is orientated. Set Start and End uses local space, so you have to convert them using the node
The end result:
Thank you guys for your support!