# Python script to set viewport to newly created camera

**URL:** <https://forums.unrealengine.com/t/python-script-to-set-viewport-to-newly-created-camera/253574>\
**Category:** Editor Scripting\
**Tags:** unreal-engine\
**Created:** [October 1, 2021, 3:51am UTC](https://forums.unrealengine.com/t/python-script-to-set-viewport-to-newly-created-camera/253574 "2021-10-01T03:51:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_afb24263](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_afb24263](https://forums.unrealengine.com/u/anonymous_user_afb24263)\
**Post date:** [October 1, 2021, 3:51am UTC](https://forums.unrealengine.com/t/python-script-to-set-viewport-to-newly-created-camera/253574/1 "2021-10-01T03:51:36Z")

</div>

Looking for some help to try and figure out how to set the active viewport to look through the newly created camera, via Python and outside game mode.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_afb24263](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_afb24263](https://forums.unrealengine.com/u/anonymous_user_afb24263)\
**Post date:** [October 5, 2021, 6:19pm UTC](https://forums.unrealengine.com/t/python-script-to-set-viewport-to-newly-created-camera/253574/2 "2021-10-05T18:19:58Z")

</div>

Well I guess not much help on here. Took me hours to figure this out. Really wish there was better documentation for Python users in Unreal dev:

unreal.VCamBlueprintFunctionLibrary.pilot\_actor(camera\_actor)

---

<div class="post-metadata">

**Author:** ![cgsquirrel2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cgsquirrel2](https://forums.unrealengine.com/u/cgsquirrel2)\
**Post date:** [October 20, 2021, 11:23pm UTC](https://forums.unrealengine.com/t/python-script-to-set-viewport-to-newly-created-camera/253574/3 "2021-10-20T23:23:29Z")

</div>

You could also try

```auto
#Select a camera in your level
actor = unreal.EditorLevelLibrary.get_selected_level_actors()[0]
unreal.EditorLevelLibrary.pilot_level_actor(actor)

```

---

<div class="post-metadata">

**Author:** ![Mike\_McR](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mike\_McR](https://forums.unrealengine.com/u/Mike_McR)\
**Post date:** [November 27, 2023, 7:42pm UTC](https://forums.unrealengine.com/t/python-script-to-set-viewport-to-newly-created-camera/253574/4 "2023-11-27T19:42:58Z")

</div>

> [@cgsquirrel2](#):
>
> ```auto
> #Select a camera in your level
> actor = unreal.EditorLevelLibrary.get_selected_level_actors()[0]
> unreal.EditorLevelLibrary.pilot_level_actor(actor)
> 
> ```

That helped me a bit, thanks! I’m working with a level sequence and trying to do this, but I noticed it only works if I’m using a cinematic viewport and not a regular one. Is there a fix for that? Also I’ve noticed that in the sequencer it doesn’t actually ‘pilot’ the camera…this command won’t click the little camera icon in the track.
