🤑 Indie game store🙌 Free games😂 Fun games😨 Horror games
👷 Game development🎨 Assets📚 Comics
🎉 Sales🎁 Bundles

Scene detection via script?

A topic by Tahlwyn created Jan 18, 2016 Views: 620 Replies: 5
Viewing posts 1 to 5

Is there a way to get if a scene is currently active in the game via code?




(Edited 3 times) (+1)

I just looked at the API documentation and the only thing that I could see was loading and appending scenes.

I guess a work around would be to create a global variable called activeCamera in your startup script and set it to Sup.getActor("NAME OF CAMERA") in your awake method, make sure all the cameras in the different scenes have unique names. You could then use the .isDestroyed() method to check if that actor/camera is still on the screen or not. (I'm assuming an actor gets destroyed once a new scene is loaded but just in case it doesn't you can always call the destroy() method just to make sure).

Another possible way is to create a function that sets that camera to not visible (again using global variables so other scripts can access it) and then loads whatever scene you want, that way you can return whether or not that camera is visible anymore in another variable and compare it. This would probably be long and have a lot of turning visibles on and off.

This is just speculation and probably doesn't work, I'm still browsing the documentation as we speak but I hope this helps a bit. I'll let you know if I find anything else!

(Edited 3 times) (+3)

I don't think there's a built in function just yet, but until then you could just wrap the Sup.loadScene() function in another one and store the active scene manually. You can paste this somewhere in a new, empty script and it should work:

let activeScene: string;

function loadScene(sceneAsset: Sup.Scene)
function loadScene(sceneAssetPath: string)
function loadScene(scene: any){
    if(typeof scene == "string") {
        activeScene = scene;
        activeScene = scene.path;

Then you'd just use loadScene() like you normally would with Sup.loadScene() and it will store the current "active" scene for you to access when needed.


if(activeScene=="Level1") {
    // Do stuff :D

I made the function save the activeScene as the path instead of the name, since it might be useful to store it later. Like when leaving an area, you could store the activeScene in another variable. You can easily change scene.path in the last line to scene.name if you'd just like to keep just the name of the asset.

Hope this helps :D

EDIT: I updated this script here, so that it's all handled by the builtin function Sup.loadScene.


That's a much better explanation than my one ha, this should work!


What LukeLanFaust explained is the way to go. There will not be a built-in system for that because there is absolutely no concept of active scene in the engine. Sup.appendScene(...) will create some actors and stuff from a data structure. Sup.loadScene(...) do the same, except it will destroy all current actors first.

But once a scene is loaded (or appended), you can create or destroy anything you want. That's why an active scene doesn't make very much sense.

I hope that's clear enough :)

Hey all, I understand that function of loadScene takes argument of "sceneAsset: Scene", how can one make an object of type Scene programatically so as to keep it as a structure in memory?