How to detect object on mouse click

Hey Guys! I’m pretty new to UE. I’m just playing around with top down template.

I created my own player controller and set the right mouse click to move the player. Its working fine. I tried creating a left mouse click event to select the player and show its name in the log message. I tried using “Get hit result under cursor by channel” but it didn’t work.

Please tell me how to detect the different objects the mouse is clicked on.
Thank You.

Hi, well one easy way would be to add a box to the player-character blueprint, you could use a static mesh ,
than add events to static mesh, process would be something like this:

  1. Import a Static Mesh and name it, then right click–> Copy Reference !
    2.Go to your Blueprint , in the “Components” tab click “Add Component” and select “Static Mesh”, in the settings for Static Mesh Component paste the reference to your imported mesh.
  2. A little lower find the “Events” section rollout, there click and select what you want , for example “On touch”, “On Click” , and add the functionality in the graph.
  3. The last thing would be to make the Static Mesh invisible, one way to do that would be to simply un-check the “visible” parameter in the Rendering rollout or you could apply an invisible material to it, create a material and try Mask mode and give a black color or small black texture to the “Opacity Mask” slot.

Then you could also cast your Gamemode blueprint to player character blueprint and store the reference in a variable. So you could trigger nodes and functions in the gamemode blueprint. Something like this(just an example from my project):

The other way would be to iterate through actors and search for what you have clicked on, doing line trace or using for each loops or iterator functions in code.