How can I get a permanent crosshair overlay on my viewport/editor mode?

I can only get a crosshair with the begin play node, but I want to have a permanent overlay in the editor mode that wont change positions when I resize the viewport.

I believe this requires developing an editor plugin, which probably has to be done in C++ to add an overlay for each viewport render pass.

2 Likes

Do you know if there is a way I can just create a blueprint that will allow me to lock the 2D image in the viewport and have like a “Texture” tab or dropdown menu where I can select multiple crosshair textures?

I don’t know if that makes any sense, but I don’t want to mess around with scripting since I am not familiar with that.

You could create a post process material with a crosshair overlay texture. How To Add Post Process Material | Community tutorial

1 Like

This could possibly be a solution. I just need to know the specific node connection to target the .png to the center of the viewport. Do you happen to know the math/connection for that to happen?

I created a crosshair texture in Photoshop:

bild

In the material I add this code:

In game:

If you wish to scale the material use the ScaleUVsByCenter Material Function:

Result:

To fix the stretching, Add a TexCoord and modify the U / R channel, then offset it using an add:

Result

Edit: There is a smart solution you could use where you get the viewsize and do some trickery with the UVs. I am way to tired to finish this and make it look good, but that way you can retain the proper texture size and have it centered. I have a 1920x1080 monitor, so you might want to change the add -0.45 to something else.


2 Likes

The easiest way to do this, is to make a UMG widget that displays a texture as a picture.

Make that widget contained in a standard layout.

Make the picture positioned at 0.5, 0.5, 0.5, 0.5 and make the margins be -32, -32, 32, 32

That way, a 64x64 pixel picture will always be displayed in the middle of the area of the layout.

If you use “Create Widget Instance” of this instance, and then do “Add Widget To Player Screen” for the given player (you can use “get player controller 0” for single player clients) then the crosshair will be in the center of that player’s viewport. Works great for split screen, too!

A good place to do this might be in the player controller Begin Play callback, and you might want to store the widget to a variable in your player controller so you know to not re-create it if the same player controller is re-used for stopping/starting play again.

Sadly, 5.3.1 is downloading for me right now, so I can’t screen shot it, but it’s pretty simple to set up, if you follow any “customer Unreal player UI with UMG” tutorial or video.
Also, yes, more than one UMG widget can be added to the same screen, so this won’t interfere with any menus or inventory or whatever else you might build. Just make sure to make it not clickable and not take focus in the properties panel.

This is getting super close to what I am looking for!!

I’ve made those connections and the Add node locks it horizontally… Great! Do you know how to lock the uv vertically?

When I change the value in the add node, it moves the crosshair from left to right, but how can I make it stop moving?

The value is the same, but the viewport is different and the crosshair moves.

Thanks for yor answer! @EliasWick is getting closer to what I am looking for. If you know a way I can possibly edit the UV to lock it in a vertical position and display it as a post process material, that would help me a lot.

I just realized that it could be similar as to when you include damage effect vignettes around the borders, but I want to lock the image aspect ratio in the center rather than lock the aspect ratio in the borders of the viewport.

The viewsize node is a crucial element in this, and last night I couldn’t get it working properly. I’ll give it another shot, but I suggest you try a bit yourself in the meantime.

Hi Elias!

I actually made another post/question regarding this topic in the following link:

I included screenshots of the progress so far and I actually mentioned you as well.

Thanks for your help! :slight_smile:

1 Like