How do you spawn a “Target Box” (graphic made in photoshop) around an actor and have it follow it around. Like a missile lock?
You can achieve this using UMG (Unreal Motion Graphics), which is a very efficient HUD tool.
If you don’t know what it is I recommand you to follow some kind of tutorials (like this).
The idea is pretty basic, you create a Widget that carries your picture. You spawn it (or add it as Widget Component) on your targeted enemy and it should follow him.
Just spawn the “Target Box” on the actor and it’s location will be located to the location of it’s parent.
Or you can add a Scene Component to your actor blueprint. Then, when you need, spawn your target box in place of that scene component. Then you achieve what you want - target box attached to actor.
Use material billboard. Add that billboard in target blueprint.
Use line trace to know if you targetted something.
Break line trace result, there should be reference to hit actor (its your target).
Use that, cast to Bp_target (or whaterver its called), if successful set billboard to visible.
But there is that problem of untargetting.
To solve it every target should have intiger index that you increase every time you create one target blueprint.
Then player controller (or pawn) should have event dispatchear “you are targetted” that gives integer index of which target is targetted.
And one more dispatcher that tells “no longer a target” with integer index again.
So when you target some BP_target, use line trace get its actor reference. Then call “you are targetted” with that intreger.
Targetted BP should then make targetting frame visible.
When you lose target call “no longer a target” again with integer index. And (un)targetted blueprint should hide billboard.
At begin play each bp_target blueprint should cast to player controller and bind both event dispatchers.
And last: “Why not umg?”
It is because material billboards have very nice scaling methods. If done rith you will never be bothered with targetting box scale again.
PS. I am doing it both ways. Targetting box is billboard, and name with ID of target is done from umg.