Game Dev

A Simple Look-At Blueprint for Unreal Engine

When setting up an environment, it is sometimes useful to have a method to automatically orient objects toward a particular point in the space. A typical example could be setting up some lights to be pointed in a certain direction, or any other case where the use of the rotation gizmo could be not very precise or you need to orient multiple objects.

In Unreal Engine you can easily build a couple of tools to help the artists to perform such behaviour during the level editing phase. We need two blueprints where we will insert some logic into the construction script, which is the part of the blueprint that is executed every time you move an object or change any of its parameters:

  • A blueprint to orient an actor toward a target object every time you move the object. We’ll call it Look-At blueprint. 
  • A blueprint to reorient all the actors looking at the target every time you move the target. We’ll call it Target Look-At Blueprint.

Look-At Blueprint

In the image below you can see the Look-At Blueprint. I set up a public variable called TargetActor of type Actor. The node Find look at rotation computes the look-at rotation between the actor and the target location. This rotation is applied to the actor by the SetWorldRotation node. If you want to apply this behaviour to an object in your level, for example to a static mesh, you have to create a new blueprint class extending this Look-At class. Then you have to add the static mesh to the blueprint hierarchy (simply drag and drop the mesh from the content browser to the blueprint editor window). Now you can compile the blueprint and you are ready to put it in the level. Once you have the blueprint actor in the level, you can select it and go to the details panel; her you will find the Target Actor variable, where you can set a target actor (see the video at the end of this article).

LookAt

Look-At Blueprint construction script

Target Look-At Blueprint

Below you can see the target look-at blueprint. Here I created a public variable called LookAtSource of type array of actors. The construction script simply loops over all the look-at source actors and sets their rotations making them look at our target actor. As we have seen in the blueprint above, you have to subclass this blueprint, add your target object to its hierarchy (if you don’t need a target object visible in game you can leave it empty), add the blueprint to the level, go in the detail panel and set the array of look-at sources in the Look At Source variable (see the video at the end of this article.

TargetLookAt

Target LookAt construction script

The following video shows how to use these two blueprints.

4 thoughts on “A Simple Look-At Blueprint for Unreal Engine

    1. Giuseppe Post author

      The look-at logic I’m explaining here is implemented in the construct method. If you need to look at the player, you need to add some logic to the tick event in the event graph.

      Reply
      1. Matthew Porcaro

        What logic would you add to the graph to get this to function at runtime? Do I just build these blueprints in the graph on Event tick instead of construct?

        Reply
  1. Pascal

    Hello
    it seems that both Target and Look-At are not available anymore in 4.18.. Or were they replaced by something else?
    I wanted to create a camera target for a cinematic..
    Thanks in advance..

    Reply

Leave a Reply