let say I have two scenes in unity I want to load Scene based on URL how can we achieve that?
for Eg: ./Scene1 for sceneindex:0 and ./Scene2 for SceneIndex:1
by user 406778568597831690
let say I have two scenes in unity I want to load Scene based on URL how can we achieve that?
for Eg: ./Scene1 for sceneindex:0 and ./Scene2 for SceneIndex:1
by user 406778568597831690
What you can do right now is:
What I want to add is a feature to load them by scene name as well (e.g. scene=myFirstScene
and scene=myOtherScene
) - I will add it as an task internally again
Depending on your project setup you can also use something like a router (e.g. via sveltekit, vue or react) where you load e.g. different pages based on the current website url OR where you can just switch the attribute based on the current url. We don’t have a public example for that right now tho
I added support for switching by name for the next update (will probably be released tomorrow!)
@TNTCF4 just published this in v3.9.1-exp
i tried this its doing the Additive load of Scene, am looking for complete reload of Scene and When i Tried using Asset Reference its not accepting scene in Asset Reference, I was trying to load Scene as per my convenience.
import { AssetReference, Behaviour, serializable } from “@needle-tools/engine”;
import * as utils from “@needle-tools/engine”
var scene1 = utils.getParam(“scene”);
var lobby = utils.getParam(“UIbutton”)
export class sceneloader extends Behaviour {
@serializable(AssetReference)
Scene1?:AssetReference;
@serializable(AssetReference)
Scene2?:AssetReference;
async start() {
if(scene1)
this.Scene1?.instantiate();
else(lobby)
this.Scene2?.instantiate();
}
}
by user 406778568597831690
Hi, you can use the SceneSwitcher for this (no need to write a custom component)
AssetReference does accept a SceneAsset or a Prefab (you have to drag it from the Unity assets into the slot)
When you load scenes like this you’re just adding them to the current scene. You have to destroy loaded scenes if you want to remove them again.
There’s also a custom example for loading scenes in the samples package and the docs
But usually I’d recommend you use the scene switcher (it also has an API that you can use to switch the scene from script if you want)