Original Post : https://unrealidiot.com/unreal-engine-4-default-camera
In this Unreal Engine 4 tutorial I will talk about how to change the “default camera”.
For one of my projects (A 2D side scroller) I wanted to have a camera actor as opposed to a camera component attached to a player character, like in some of the engine sample projects.
I also wanted to have full control of the behavior of the camera and I did not want to worry about the camera after the character was destroyed. If you think about it, if the camera is attached to the character as a component, once the character is destroyed so is the camera.
Here is how I went about getting it done. Keep in mind that this is just one way to go about it.
THE GAMEMODE BLUEPRINT
GameMode blueprint event
BeginPlay we loop through all the actors or type
DefaultCamera and look for the one also tagged
DefaultCamera and store a reference to it. We then call
Set View Target with Blend to “aim” the camera at the player. Looping through all the actors of type
DefaultCamera may seem overkill but it allows me to re-use the class but have only one be the main or default one.
My apologies for picking a tag name that is also the name of the blueprint.
MainCamerawould have been a better choice.
DefaultCamera is a simple blueprint I created to program the logic of the camera movement.
THE CAMERA BLUEPRINT
While I chose to adjust the camera under the
GameMode, you can also do it in the
BeginPlay event of the actor containing the camera component.
For this game, after the character dies, the camera stops moving (since there is no character to follow) and a retry UI is presented. If the player desires to play again then we reload the level.