Spawning Objects to the Current Scene from Other Scenes in Haxe

Good day guys. I have two Scenes, Scene1 and Scene2. Scene1 has an object called ‘Cube’. Scene2 has an object called ‘Sphere’. My current active Scene is Scene 2 and I would like during game time to Spawn the Cube from Scene1 to Scene2 at the exact same position as the sphere. How can I achieve this using Haxe code?

I’m not sure if there is a built-in function for this, but for now it is possible using this rather ugly workaround:

Data.getSceneRaw("Scene2", (raw2: TSceneFormat) -> {
	// Temporarily set the raw scene data to the raw data from "Scene2"
	var tmpRaw = Scene.active.raw;
	Scene.active.raw = raw2;

	Scene.active.spawnObject("Sphere", null, (obj: iron.object.Object) -> {
		// The object already spawns at the correct location
	});

	// Reset the scene data to its original state ("Scene1")
	Scene.active.raw = tmpRaw;
});
4 Likes

Thanks very much @timodriaan, your code worked beautifully. I managed to achieve what I intended to do. Thank you

1 Like