(Self-Hosting) Using URL to set attributes

Hello everyone,
I need some help with self-hosting and engine communication.

What I want is that, on start of the Application, a scene (the name of which is unique and functions as an ID) is loaded based on the path/ a query of the page URL. So in my mind, it looks something like “myselfhostdoman/the-scene-id” or “myselfhostdomain/index.html/?the-scene-id”.

For the scene loading, I used the script from this demo https://developer.playcanvas.com/en/tutorials/changing-scenes/, which works nicely.

Now for the URL part, I’m completely lost. My experience with html and web development (besides javascript) is severly limited, so I have no idea if this is even doable.
So IF it is, how would one go about the task? If anyone has any suggestion, I’d be very much thankful.

Greetings

Hi @twe,

Yes, you can use some basic Javascript to get the scene name from a url parameter.

For example:

// example url https://playcanv.as/b/Fij349E/?sceneName=SceneA

// using window.top to cover the case your build is running in an iframe
var url = new URL(window.top.location.href);

var sceneName = url.searchParams.get("sceneName");
console.log(sceneName);
2 Likes

Works like a charm, @Leonidas
I honestly didn’t think it’d be this simple.
Thank you very much!

1 Like