Problem with getSceneUrl


I am trying to check whether the scene matches a certain url, but this is not working. My code is as follows.

if ( === '843344') {

Is there any reason why check is not returned to the console?

getSceneUrl is a function, not a property:

I also think that the way you want to use it isn’t what the function is for.

Is there any way to do what I need to? It returns the following.

function(name) {
    var entry = this._sceneRegistry.find(name);
    if (entry) {
      return entry.url;
    return null;

I assume that you want to know what scene is currently loaded?

The easiest way is to keep track of it yourself or have a script at the root of each scene that adds/removes the scene name/id to a global list.

Essentially, there are three races in a tier in our game. The car should only upgrade if a button is clicked in the first two of those races. That’s the purpose of checking the scene, since the races are individual scenes. I can’t keep track of that myself. Will the script at the root solve this?

Are you loading scenes additively? (ie multiple scenes at once?)

My project is Please take a look, I’m not sure.

As far as I can tell, you are not loading any scenes and the UI is cloned in multiple scenes (it’s not the way I would do it for maintenance reasons but that’s a separate issue).

You can solve this a few ways:

  • Add a boolean attribute to whatever script is managing the UI that controls the enabling or disabling of the upgrade button. That way you can disable the upgrade button on a per scene basis
  • Add a script that when initialize is called, adds a scene id/name to a global list and removes it on destroy. This allows you to query the list when you need to check what scenes have been loaded
  • When you do write a race scene load, keep track (in a global variable or something) of what race scene was selected by the player

Thanks, I’ll try it out later.