Download

Question from a newbie.

Hello guys, i used UE4 for couple days and ran into this error. This only happen if i click outside the test dummy.
[SPOILER]

[/SPOILER]

Here is my Blueprint

[SPOILER]

[/SPOILER]

My plan was making a Click to attack like other top down RPG game. I tried set up this system in Player Controller Blueprint but it didn’t work well so i move it to character sheet and found out i can’t use left mouse button. I want to make my character use left mouse to move, if the target is far my character will move close to it and attack. The build in mouse-click-moving from the Top Down Template isn’t good enough)
I’m looking for advices from you guys about making move and fight melee combat smoother than this trash.

the error probably comes from the linetrace not hitting an object and therefore not having an object to get its location from, so you get the “acessed none” error. You can fix that by checking if the hit result is valid before trying to read the porperties of the hit object. For the code itself, instead of line traces you can also use box or sphere colliders wich have an “on event begin overlap” event built in, that olny triggers when there actually is something to overlap. You can place those coliders in the area, where you expect your character to be able to hit something.

So the basic concept with Colliders is: Everytime i click it will create a Collider to check is the player clicking on any interactive objects then play with Overlap event. Sound interesting, i just played with sphere traced function recently.
One mini question: Can i put Blueprint of movement, clicking, attacking in PlayerController BluePrint or just put it on my Character Blueprint, i want those things kinda global system so if i select another Character, it will work also and i don’t have to copy paste it for each character.

Thank you for your answer once again.

or the collider is always there and only activated when clicking, you dont have to create a new one every time.
I you want the clean version, you would put the movement system in the controller BP and the attacking system in the character BP, beacuse you could also have a secound character, wich will also use the movement funktionality, but cant attack or attacks differently. Also if you want to create AI controlled characters, they will need the attack functionality but use a different movement system. Depends on what type of game you have in mind.

Thanks for yor reply. There is a little problem if i put the attack click and the movement click in seperated BP, the controller will overdrive my left mouse but so i couldn’t use it in my character’s BP. Is thre anyway to recover Left mouse button event or should i use another button (rightclick for instance)

normally you shoudl handle all inputs in the controller blueprint to avoid something like you described. In the controller blueprint you can then choose wich action your mouse click should perform. If your mosue click should activeate an action in your character BP, you can always cast the action to the blueprint it is needed. But the input event itself is in the controller BP. IF that doesnt solve your problem, maybe actually use another button, in this case you should consider what the player will expect the button to do if he presses it, for exmaple always use the right click to move the character and left click to attack, so the player would not get confused by changing input actions. IDK if that would apply to your specific case, but just to keep that in mind as well.

Ty for your support, i finally can make my character run to a target then hit it with the same Left Mouse Button, but it isn’t smooth, if my character is far from the Target it will run to the target then i have to left-click once again to performe the attack animation. I tried to use AI move to, but it doesn’t fit player controller input.