# How to change camera type without creating new camera and using detachcontrol

**URL:** <https://forum.babylonjs.com/t/how-to-change-camera-type-without-creating-new-camera-and-using-detachcontrol/4007>\
**Category:** Questions\
**Created:** [June 20, 2019, 10:05am UTC](https://forum.babylonjs.com/t/how-to-change-camera-type-without-creating-new-camera-and-using-detachcontrol/4007 "2019-06-20T10:05:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anes](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Anes](https://forum.babylonjs.com/u/Anes)\
**Post date:** [June 20, 2019, 10:05am UTC](https://forum.babylonjs.com/t/how-to-change-camera-type-without-creating-new-camera-and-using-detachcontrol/4007/1 "2019-06-20T10:05:37Z")

</div>

Hello guys,  
I want to switch from arcRotateCamera to UniversalCamera by toggled switch, I want to use the same var camera and not creating a second one and detachcontrol the first and attach the second.

thank you

Anes

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [June 20, 2019, 10:32am UTC](https://forum.babylonjs.com/t/how-to-change-camera-type-without-creating-new-camera-and-using-detachcontrol/4007/2 "2019-06-20T10:32:38Z")

</div>

The scene has two functions that could help you:  
`setActiveCameraByName` and `setActiveCameraByID`, so you can create two cameras and switch between them.

---

<div class="post-metadata">

**Author:** ![Anes](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Anes](https://forum.babylonjs.com/u/Anes)\
**Post date:** [June 20, 2019, 1:44pm UTC](https://forum.babylonjs.com/t/how-to-change-camera-type-without-creating-new-camera-and-using-detachcontrol/4007/3 "2019-06-20T13:44:23Z")

</div>

this is using detachcontrol and then make scene.activeCamera , me I want to use the same camera and then with the toggled function I switch between them.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [June 20, 2019, 3:09pm UTC](https://forum.babylonjs.com/t/how-to-change-camera-type-without-creating-new-camera-and-using-detachcontrol/4007/4 "2019-06-20T15:09:09Z")

</div>

Maybe something along these lines:

```auto
var switchCamera = function () {
    var camera = new BABYLON.FreeCamera("newCamera", scene.activeCamera.position, scene);
    if (scene.activeCamera.rotation) {
        camera.rotation = scene.activeCamera.rotation.clone();
    }
    camera.fov = scene.activeCamera.fov;
    camera.minZ = scene.activeCamera.minZ;
    camera.maxZ = scene.activeCamera.maxZ;

    scene.activeCamera = camera;

    scene.activeCamera.attachControl(canvas);
};

```

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [June 20, 2019, 3:10pm UTC](https://forum.babylonjs.com/t/how-to-change-camera-type-without-creating-new-camera-and-using-detachcontrol/4007/5 "2019-06-20T15:10:24Z")

</div>

Couldn’t you trigger the setActiveCamera function in the toggled function?  
So, you have, for example, HTML Button with a click function attached to it, and the event is firing the camera switch.

---

<div class="post-metadata">

**Author:** ![jvanderdoes](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jvanderdoes/32/31978_2.png) [@jvanderdoes](https://forum.babylonjs.com/u/jvanderdoes)\
**Post date:** [June 26, 2023, 9:20pm UTC](https://forum.babylonjs.com/t/how-to-change-camera-type-without-creating-new-camera-and-using-detachcontrol/4007/6 "2023-06-26T21:20:38Z")

</div>

@RaananW sorry to bring this thread back, but I’m a bit curious, is there a design motivation for having the camera mechanics coupled to the camera itself? When I got started with babylon.js I sort of expected things like `ArcRotateCamera`, and `FreeCamera` to work the way the camera input system works - you’d attach some behavior to a renderable camera.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [June 26, 2023, 9:23pm UTC](https://forum.babylonjs.com/t/how-to-change-camera-type-without-creating-new-camera-and-using-detachcontrol/4007/7 "2023-06-26T21:23:30Z")

</div>

History and Back Compatibility are the only reasons 🙂

---

<div class="post-metadata">

**Author:** ![jvanderdoes](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jvanderdoes/32/31978_2.png) [@jvanderdoes](https://forum.babylonjs.com/u/jvanderdoes)\
**Post date:** [June 27, 2023, 2:20pm UTC](https://forum.babylonjs.com/t/how-to-change-camera-type-without-creating-new-camera-and-using-detachcontrol/4007/8 "2023-06-27T14:20:28Z")

</div>

Good reasons. Thank you for the context.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [June 27, 2023, 2:56pm UTC](https://forum.babylonjs.com/t/how-to-change-camera-type-without-creating-new-camera-and-using-detachcontrol/4007/9 "2023-06-27T14:56:24Z")

</div>

NW I know how things are confusing even for us sometimes but considering 10 years of history, it could be a lot worse 🙂
