Matt574 Posted December 8, 2015 Share Posted December 8, 2015 Hi Guys, I'm relatively new to Babylon.js and from what I'm seeing so far it is an excellent tool! I am however having a slight issue with scene.dispose(). I've noticed that when I call this method pointer methods no longer work. so I have an onPointerDown event which works fine before scene.dispose() but after I call it the pointer down no longer works! What can I do to re-enable this after I dispose a scene? Also what other properties need to be re-activated after dispose? Many Thanks Matt Quote Link to comment Share on other sites More sharing options...
RaananW Posted December 8, 2015 Share Posted December 8, 2015 Hi Matt!Welcome :-) First, just to understand - why do you need to use the scene.dispose() ? The scene contains all of the objects that are required to... render a single scene , including user interactions (the action manager, the pointer down and up etc'). If you dispose a scene, you will have to create a new one, that will handle those events again. Quote Link to comment Share on other sites More sharing options...
Matt574 Posted December 8, 2015 Author Share Posted December 8, 2015 Hi Raanan, thanks for the warm welcome : ) Basically I want to be able to clear my scene from all meshes cameras lights etc so reset it I guess. If I create a new scene after disposing the old one the renderer seems to loose its scope and doesn't render anything. Do I need to set the new scene to be active? Cheers! Quote Link to comment Share on other sites More sharing options...
RaananW Posted December 8, 2015 Share Posted December 8, 2015 The "active scene" is the one being rendered by the engine. You probably have somewhere an engine.runRenderLoop hidden in your code. Inside you probably have a scene.render() call. You just need to change the scene reference here. BTW, you can also clear all array of the scene. But if you really want to get rid of everything, scene.dispose() would of course work. Quote Link to comment Share on other sites More sharing options...
fenomas Posted December 9, 2015 Share Posted December 9, 2015 Usually I think of .dispose methods as what you call when you're finished with an object and ready for it to be garbage collected. Wouldn't it make more sense here to dispose the old scene, drop the reference to it, and then construct a new one? Quote Link to comment Share on other sites More sharing options...
RaananW Posted December 9, 2015 Share Posted December 9, 2015 This is exactly what he is doing :-) Quote Link to comment Share on other sites More sharing options...
Matt574 Posted December 14, 2015 Author Share Posted December 14, 2015 Thanks for the reply's guys. I couldn't get the new scene method to work so i ended up just clearing out all the arrays within the scene as suggested by Raanan. However it would be great if i could get the new scene method to work. What i have is this:window.addEventListener("DOMContentLoaded", function(){ new App("appViewport"); },false);var global;var App = function(canvasID){ global = this; this.canvas = document.getElementById(canvasID); this.engine = new BABYLON.Engine(this.canvas, true); this.scene = new BABYLON.Scene(this.engine); this.assetsManager = new BABYLON.AssetsManager(this.scene);}Then elsewhere in my application when i want to reset the current scene i use:global.scene.dispose();global.scene = new BABYLON.Scene(global.engine);This doesn't appear to work. Is there a way to drop the reference to the old scene as mentioned above? Many Thanks Matt Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 14, 2015 Share Posted December 14, 2015 can you provide a repro case somewhere? This should work Quote Link to comment Share on other sites More sharing options...
Matt574 Posted December 20, 2015 Author Share Posted December 20, 2015 I will have to revisit this a bit further down the line as I can't put the project I'm doing online. Resetting the Scene arrays seems to work for now..... Thank you so much for all the help, greatly appreciated! : ) GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.