# engine.runRenderLoop() blocks my scene

**URL:** <https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262>\
**Category:** Questions\
**Created:** [May 16, 2019, 2:06pm UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262 "2019-05-16T14:06:16Z")\
**Posts on this page:** 13\
**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:** [May 16, 2019, 2:06pm UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/1 "2019-05-16T14:06:16Z")

</div>

hello guys,

So I create two cameras in the same scene and I switch to one to other with boolean variable that I recover it from an other software.

so when I change the boolean from 0 to 1 my camera moves through a specific goal and it works fine (inside move() function there is a specific path and scene.beginAnimation() function ).

the problem is when I try to turn back to initial caméra (1 to 0), it blocks on the second (I think because I use runRenderLoop() and I define scene.render() inside), so despite my changing it gards the last scene event which is my goal.

so any idea how to stop scene in order to turn back to initial view this is my code :

```
 var camera1;
 var camera2;
 var scene;
 var canvas;
 var engine;
 var activeCamera;
 var x;

  var InitCamera= function(){
  camera1= new BABYLON.ArcRotateCamera("Camera",0, 0, 10, new BABYLON.Vector3(0, 0, 0), 
  scene);
  camera2=camera1
  activeCamera="StandardCamera";
  scene.activeCamera=camera1;
  camera1.attachControl(canvas, false);
   }

 var UseCamera1=function(){

    if(activeCamera="SecondCamera"){
activeCamera="StandardCamera";
camera2.detachControl(canvas);
 }

scene.activeCamera=camera1;
camera1.attachControl(canvas, false);
  }

var UseCamera2=function(){

if(activeCamera="StandardCamera"){
	activeCamera="SecondCamera";
camera1.detachControl(canvas);
 }
  scene.activeCamera=camera2;
  camera2.attachControl(canvas, false);  
  MoveCamera();
}

 var MoveCamera=function(){
  var MyGoal = new BABYLON.Vector3(5,1,0);
  var MyCurve= MyPath(camera2.position,MyGoal);
  MoveCameraThrough(scene, camera2, MyCurve);
  }

  //---------------------------------------------------------------------------------------------------------------------------------------------------------//

 var CreateScene=function(){
 canvas = document.getElementById("renderCanvas"); // Get the canvas element 
 engine = new BABYLON.Engine(canvas, true); 
 scene= new BABYLON.Scene(engine);
 BABYLON.SceneLoader.Append("/data/html/babylonTest/", "coffrageLight.babylon", 
 scene,function(scene){
             scene.clearColor = new BABYLON.Color3(1, 1, 1);

         })
   InitCamera();
   oaJsApi.dpConnect("second.:_original.._value",true,{

     success: function(data) {

		x = data.value;

		if(x == 1)
			{
			  UseCamera1();
			}
		 else if(x == 2)
 		   {
			  UseCamera2();
   		 }

		}

		 });

  return scene
 }

var scene = CreateScene();

engine.runRenderLoop(function(){
	
 scene.render();	

});

window.addEventListener("resize", function () {
         engine.resize();
     });

```

and this is my MoveCameraThrough() function :

```
     function MoveCameraThrough( scene , camera, MyCurve)
    {
     const path3d = new BABYLON.Path3D(MyCurve.getPoints());
     const tangents = path3d.getTangents(); // array of tangents to the curve
     const normals = path3d.getNormals(); // array of normals to the curve
     const binormals = path3d.getBinormals(); // array of binormals to curve
     const speed = 30*Math.floor(Math.random() * (7 - 3 + 1)) + 3; // const speed = 1
     const animationPosition = new BABYLON.Animation('animPos', 'position', speed, 
     BABYLON.Animation.ANIMATIONTYPE_VECTOR3, 
     BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
     const animationRotation = new BABYLON.Animation('animRot', 'rotation', speed, 
      BABYLON.Animation.ANIMATIONTYPE_VECTOR3, 
      BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
     const keysPosition = [];
     const keysRotation = [];

     for (let p = 0; p < MyCurve.getPoints().length; p++) {
       keysPosition.push({
     frame: p,
      value: MyCurve.getPoints()[p]
        });
         keysRotation.push({
        frame: p,
       value: BABYLON.Vector3.RotationFromAxis(normals[p], binormals[p], tangents[p])
        });
         }
      animationPosition.setKeys(keysPosition);
        animationRotation.setKeys(keysRotation);

       camera.animations=[
       animationPosition,
       animationRotation
        ];
      scene.beginAnimation(camera, 0, 200, false);
        }

```

Thank you

Anes

---

<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:** [May 16, 2019, 2:14pm UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/2 "2019-05-16T14:14:24Z")

</div>

Hello and welcome!

> [@Anes](#):
>
> if(activeCamera=“SecondCamera”){

This seems REALLY suspicious. You may want to try with === instead of =

---

<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:** [May 16, 2019, 2:27pm UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/3 "2019-05-16T14:27:48Z")

</div>

@Deltakosh 😲 I didn’t see that,  
I change it but still the same problem can’t back to useCamera1()

---

<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:** [May 16, 2019, 2:31pm UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/4 "2019-05-16T14:31:21Z")

</div>

can you repro in the playground maybe? Will be easier to help you fix it 🙂

---

<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:** [May 16, 2019, 2:33pm UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/5 "2019-05-16T14:33:24Z")

</div>

I have blender object that I upload it to the scene from my pc how to upload it in playground ?

---

<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:** [May 16, 2019, 2:37pm UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/6 "2019-05-16T14:37:19Z")

</div>

here we are 🙂  
[https://doc.babylonjs.com/resources/external\_pg\_assets](https://doc.babylonjs.com/resources/external_pg_assets)

but honestly replace your mesh with a box and it will be enough. The mesh is not the root cause here

---

<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:** [May 16, 2019, 2:40pm UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/7 "2019-05-16T14:40:43Z")

</div>

you’re right yes, so I’ll upload it

---

<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:** [May 17, 2019, 8:07am UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/8 "2019-05-17T08:07:38Z")

</div>

@Deltakosh I try to load it but I need two buttons in order to switch between my cameras, where I can add HTML code ?  
Like this :

 ![Capture](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/5/5325b4d75cb16df7feebde4e40411d16ae803ac9.jpeg)

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [May 17, 2019, 8:23am UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/9 "2019-05-17T08:23:51Z")

</div>

@Anes  
You can use GUI,  
see lines 32 - 60  
[https://playground.babylonjs.com/#VK7STZ#1](https://playground.babylonjs.com/#VK7STZ#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:** [May 17, 2019, 8:26am UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/10 "2019-05-17T08:26:23Z")

</div>

@aWeirdo thank you I’ll try then ^^

---

<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:** [May 17, 2019, 10:44am UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/11 "2019-05-17T10:44:14Z")

</div>

@Deltakosh here is the playground [Babylon.js Playground](https://www.babylonjs-playground.com/#21HAJZ)  
when you click “button two” camera moves through MyGoal, but I want that when I click button 1 turn back to camera1 and when I click “button two” it repeats.

Thank you

Anes

---

<div class="post-metadata">

**Author:** ![sharp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sharp/32/1325_2.png) [@sharp](https://forum.babylonjs.com/u/sharp)\
**Post date:** [May 17, 2019, 3:16pm UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/12 "2019-05-17T15:16:51Z")

</div>

@Anes it is resolved now right ?

> [@How switch the type of camera](https://forum.babylonjs.com/t/how-switch-the-type-of-camera/3167/26):
>
> @sharp yesss it works blush blush hugs Thank you Anes

If so could you please mark this one as resolved too ? Thanks !

---

<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:** [May 17, 2019, 5:03pm UTC](https://forum.babylonjs.com/t/engine-runrenderloop-blocks-my-scene/3262/13 "2019-05-17T17:03:14Z")

</div>

Not sure if there is a question left? If yes please open a new thread 😃
