Crosshair in 3d space

Hi there guys! Recently I started playing with UE4, but now I;m stuck with this crosshair thing. Basically is there a way to make crosshair be a part of the 3d world and make it stick to whatever it encounter. It should slide along meshes and stick to them file facing the camera. As you can see in pictures below both of these games use something that I would like to implement in my project. Blue,yellowish flare that changes when hovered over an interactive actor. Please help me! I’m using blueprint only.

131844-american-mcgee-s-alice_5.jpg

You will have to specify what you mean by “stick to whatever it encounters”, but here are the basics: You can use just a normal sphere that represents your crosshair. If you make a static mesh component and attach it to the camera, it will always keep its position relative to the camera, so you can put it in front of it or wherever you desire. You can of course also attach it to the character if that is more suitable.

Hi there pulp_user! Thanks for answering me! I tried using mesh and attaching it to the character at a certain distance but once I’m closer to a wall for example the sphere would go just through it. Well it should slide just like a laser point.

Ok this requires some gamplay logic. What you want to do is the following: You want to do a sweep each frame . What that means is you move the sphere (invisibly) from inside your character (a place where it is not blocked by anything around it) towards the position it should be in. Sweeping will try to do that, but if it is blocked by something, it will stop right where the block occured. (This link provides a very good explenation of what that stuff actually does)

In blueprint that would mean: create a first SetRelativeLocation node that sets the sphere to its starting point inside the characters head for example, and then follow it up with a second SetRelativeLocation node that sets the sphere to the position in should be in if it doesn’t hit something. Only in the second node you tick the Sweep box. You will have to do this in the tick function each frame.

Since you do these movements before the scene gets rendered it will seem like the sphere will simply stay where it is, or retreat a bit if you hit a wall.

You also have to ensure that your collision settings for your sphere are correct (it should probably block your walls and such, but not your player, since it would be stuck inside of his head then).

I tried what you told me, it gives promising results but the mesh still goes through walls. I tried different types of collision. Here is my blueprint, maybe I’m doing something wrong. Tthanks for helping me!!

Ok this graph looks a bit dodgy :smiley:

There is no need to spawn an actor each frame, You can simply, in the blueprint viewport, attach a sphere component to your camera. This is my setup which works fine:

If you take the sphere component, you don’t even need to check for collision, it defaults to the right settings. Spawning an actor is also not really necessairy since your crosshair probably should belong to your character anyway if it moves with him. It’s just a mesh, it doesn’t need its own actor.

Oh god I’ve been trying to make this work for days, but still no results :confused: I’m stupid sorry, could you please explain me if I did something wrong step by step. I created an actor with this box mesh (it’s just for testing purposes) then I created child actor in my main character BP and set it to be my crosshair actor. I attached it on left click and added the stuff you told me. But the cube thing is still going through walls and meshes. I’ve noticed it doesn’t go though static meshes that have physics on…but it pushes them. Here are the pics. Sorry if I’m bothering I’m relatively new to Unreal

I tried doing this without attach component function but it still goes through walls as you can see in my first pic :frowning: I’m gonna die and I won’t make my 3d crosshair

Oh I think I got it I parented player pawn to the cube and now it’s working thank you so much!!!

but when I start the game I get these warnings. Anyone know what they mean? Maybe I’m not doing this right

It seems like you are trying to re-attach the root component to another component each frame? this is not necessairy, you can simply add the sphere component under tha “add component” section on the lefthandside and drag it onto your camera component. You do not need to create or attach it at runtime!

Thank you so much now my project is error free! I used timer function instead of tick event so I can easily shut the loop down when it’s not needed anymore. Thank you again you’re a life saver!

Glad I could help! Please accept the answer. (So I get these sweet forum points :D)

Ok I didn’t know I could do that :smiley: But I’m running into another problem now with my stubborn crosshair. Whenever it overlaps an actor with specific tag it should change it’s material. It works when I add EventOnComponent overlap and it really does change material but as soon as I add on EndOverlap it doesn’t change the material it stays with it’s original one. Here’s the pic

This should be a new question! Your last problem was solved :D. At first glance I can say that I don’t see any mistake in this graph. You don’t check if the actor that is causing the end overlap is the same as the one that started the last overlap, which might cause problems if you are overlapping 2 actors at once, and leave one, it will set the material to default eventhough you are still in another actor. This should not be what causes your current problem though. Try to debug when exactly those events fire, maybe you are overlapping something that you are not aware of. Check if the overlaps occur exactly in the order they should occur in.

I seem to resolve this problem by increasing the collision size of my actor. When my crosshair overlap the actual actor it doesn’t change its material but if it overlaps its collision it does and it changes to default one when its end overlapping. If the problem persists I’ll open up a thread with a new question :slight_smile: