Clicking on an object in the world to change camera view

Hello everyone,

I am very new to Unreal Engine so I may have some fundamental misunderstandings about what I am doing – please feel free to correct me in any way.

My desired behavior:

Using the first person character, put the crosshair over the monitor and click. When clicked, the camera view will change to a specified Scene Capture 2D camera. I would like this behavior for arbitrary pairs of monitors and cameras.

I have imported the asset for a computer monitor to my level. It looks like this:

Originally I had a mess of code using OnClicked in the Level blueprint:

This approach had 2 problems.

  1. The crosshair and the mouse cursor do not necessarily line up, so the clicking did not always work properly.
  2. I would need to create a separate event for each computer/camera combo, I already have 17, so I can see this approach getting out of hand.

I was able to set up a line trace on my character and find it intersect with the computer:

The main problem I have is that I am unable to find a streamlined way to associate the specific computer monitor in the world with a specific camera. I also don’t really understand where to put that logic – unless I am in my level blueprint I have been unable to successfully get a reference to the specific camera like I have here:

Can anyone set me on the right track? I would really appreciate it! If it matters, I have some working knowledge of interfaces but without getting the camera reference I am struggling to figure out how to use interfaces to dispatch to a specific camera.

I also tried creating a map that associates StaticMeshActors with CameraActors but it wasn’t working – even when I had the CameraActor selected, I could not populate the Value field of the map with it. It was the correct type.

Thanks in advance!

Hi man, sure

1 Yes the crosshair and the mouse are two different things, you have to be carefull design your blueprint.
if you only have to click on giant things like monitor, you can work with tthe crosshair.
If you want be able to , click some codes on a digital-door-lock, you may want to add the mouse switch.(you can also set the mouse visible and invisible…)

2 Yes, you dont need to create a separate event for every camera combo, i tell you down… :slight_smile:

Good this is good ,
from a linetrace you can get the reference to the object too,
break the hit info (right click - break) you will be able to find the “other actor” pin
if you make the raycast from the character player, he will be able to check, what he have raycasted,
is the actor class an staticmeshactor class? (if you drop a staticmesh in the level, it will become an staticmeshActor)
The actor have a mesh component of type monitor? (the mesh of the staticmesh can be a cube, a couch, a lamp, a statue, or a monitor)

You can do this in a lot of ways, let me tell you 2.
1, drop the monitor in the level, and select it, select the detail on the right, and search for the ActorTag.
You can give this actor a string to identify him.
In the blueprint of raycasting, then, you can pin out the other actor, and use the node “Has tag” to know if that actor have a specific tag.
The tag could be the name or the rag of the camera you want to pair. so you can make a full list of :
If has tag camera 1, set player view to camera 1
If has tag camera 1, set player view to camera 1
2Make a monitor blueprint instead of leaving be a staticmesh actor.
You can create the blueprint, add the static mesh, add some variables and custom events to manually write only 1 time.
like, If the player click on monito, monitor call event, set your custom view,
And you can have a editable variable to set, so you can drop this monitor and just change the camera you want to use for every one.

The level blueprint knows the thing you place in the level,
Like the actor knows the component you place in the actor.

For connect the things inside the level, to the actor, is something that usually you do with casting or collisions.
The level blueprint purpose is to manage little thing level–only like floating platform or doors.
For more complex things you can just place another actor call it “MonitorManager” and try to manage to cast , and store all your info.

Like before, is true that you can event-dispatch all way back and up but is a huge work for nothing,
For example any actor can use “get all actor of class” to get all the actors in the level of type.
Than you can loop all them, and search for specific things.
Or you can get the actors from raycasting or collisions, or by distance.
Once you get the reference, you can call to the actor.

Sorry for big answer
let me know if you get it