Make a Scene using Code

I want to make a Scene in Gdevelop! Is there a way?
Even if it means using Java.

Because I am currently messing around with procedural generation and I would love not to make a thousand Scenes so I don’t have a lot of useless scenes where only one or two are going to be used!

Thanks in advance!

Procedural generation is exactly what you need.
I remember a few topics on the forum about that.
But who would play a thousand scenes? :smirk:

I think javascript is the only lang. you can use in GD.

Sadly there is nothing about adding a new scene only unloading and loading one. :cry:

Thanks for your effort though!

What’s stopping you from taking a scene, clearing out all the objects (or all objects on a layer or layers) and adding new objects? Or have I got the wrong end of the stick?

@MrMen I don’t want to make a limited amount of scenes to the player because if I do that I am going to limit the player to have 10 scenes as an example. If I am messing with procedural generation which means making a pseudo-random I need to let the people player have unlimited of these.

The best way to go about this in GDevelop is using external layouts.
You can design and store parts of your scene (rooms, corridors for example) in external layouts and load them randomly as you need them whenever you start the scene. So essentially you need only 1 scene and a bunch of external layouts.
Certain objects could also have multiple animations that you choose from which one to display if you want a barrel or crate for example to make it even more random.
But obviously you need to come up with a smart algorithm that generate a fun and playable scene from the external layouts.

If you want anything more serious than that, in my opinion it is waste of time to use GDevelop you only going to find your self trying to work around the limitations of the engine. You should use a framework instead since you be coding most of the things anyway, you also don’t really need a level editor as you want to generate it procedurally so then it is makes more sense in my opinion to code everything in a framework like Phaser, MonoGame, AppGameKit, SpriteKit, CerberusX, BlitzMax and similar…


No, you misunderstood what I meant. I don’t mean adding the objects in the editor. I meant via your procedurally generating function.

What’s stopping you from deleting all the objects in your scene (or on a layer or layers) from within the function, and then adding new objects also from within the aforementioned function?

So you use the procedurally generating function to reset the scene based on a seed.

@MrMen he idea is that I don’t want the scene to be regenerated with a certain seed every time. That would just take a very long time to load especially if there is more stuff that needs to be spawned.

And I want the player to have scenes like in terraria or Minecraft, so it is a world that you can load anytime the same generate once and have an infinite amount of worlds.

@ddabrahim what do you mean using external layouts? Is there a way to “code a new external layout in” so that I could have infinite of them?

Well this is really just so I can understand how something like procedural generation could or couldn’t work. So this is just for experimenting purposes.

Minecraft creates worlds based on a seed.

So I don’t understand what you want. Either it’s procedurally generated with a seed, and the same for that seed every time. Or it’s random every time.

Or do you mean that you want the scene generated with code, and then save it, so it can be loaded later on? In which case, I’d recommend looking into GDevelop storage.

You don’t t have to code it to make it infinite. As I mentioned you need only 1 scene and you can store parts in external layouts that you can use to build a scene from each time you restart that 1 scene. So you get a different result each time you start the scene = you have infinite scene.

What I am recommending is not really procedural generation but this is what I recommend to do, to build the level from external layouts but if you really want to generate entire levels from scratch, piece by piece then in my opinion you should consider to use a framework.

Procedural generation means you are using a math formula to decide where the trees going to be, where the roads and houses going to be. Once you have generated the map, you still need to load the resources like images, sounds and create the sprite objects from the images, position them in a way that makes sense, put grass on top, dirt below, trees on ground, water in valleys and fishes in water, birds in the air…etc and then generate collision meshes and render the final results. In GDevelop it is not possible to load/unload resources as you need them, you have no control over that aspect. You are also not able to create Sprites on the fly or to modify image points and collision shapes in code, in GD you are limited to hand crafter Sprite objects and collision masks only. Even if you take the time and effort to use JavaScript to access the very core of GDevelop and load, generate assets from code, it is going to be painful because you constantly need to work around the limitations the engine and compiler put in your way.

This is why I recommend to either use External layouts to only generate levels from random layouts and random objects with random animations or use a framework instead of GDevelop if you are really serious about this and you really want to go for true procedural generation. GDevelop is not the right tool for that in my opinion not even if you are ready to code in JavaScript, especially if you are you should consider a framework.

1 Like

@MrMen Yes that is exactly what I mean. I want to save the world so that the player can access same seed and everything would be the same as they left it the last time (if they build something it shouldn’t get “deleted”)

You can use storage events to save, take a look at the “level editor” example included with GDevelop.
So to stick to what I was recommending, you can generate the level from layouts and then save using storage events and then load next time or generate a new level…

@ddabrahim that is an awesome example but my problem with that is, that it is creating the objects when the scene loads which means if you have an entire world with like 2000 different blocks, it would take a very long time for them to firstly create the objects and then after that actually render.

But thank you anyways for your efforts.

Yes and this is exactly the point I am trying to make here. I don’t believe you can improve the loading time in GDevelop without getting deep down to the rendering engine and asset management. If you want to go crazy with procedural generation and looking for an optimal result you really need to go with a framework. For example, if you go and use a rendering lib like Pixi.js, you could possibly do what Minecraft for example, you can start rendering only what the player can actually see and load everything else in the background asynchronously while the player is playing the game, no need to wait for everything to be loaded but only that the player immediately need. Potentially you could even load assets in to a container and draw the container with a single draw call. You can not do things like this with GDevelop, it doesn’t give you this level of freedom. the best you can really do is layouts in my opinion.

@ddabrahim So this the most anyone can do.

It still bothers me why they have a noise extension that really is useless because it would be very hard to work with the limitations of this engine.

Anyway thanks to everyone who commented and thank you all for your help.

I guess there really is no way to make this work.

I think because there is no real plan and roadmap behind GDevelop. Contributors usually just pick a random thing they find interesting and do it just for fun with no real plans and use cases in mind. Probably the dev contributed this extension did find a lib to generate noise values and thought it could be interesting to work with and to have it in GD and that’s it really. No further thought was put in to it maybe. But I could be wrong, wondering if there is any example demonstrate how and when this extension is meant to be used maybe?

The perin noise is awesome for camera shakes.
And you can use it to create small random generated levels.
For a turnbased rpg with small random generated battle maps (like 20×20 tiles) it works really well.
Generating entire world takes forever to load tho.

1 Like

The current Javascript API can’t offer the possibility to create a new scene from scratch like it can’t be possible to create an object (even if it’s doable, but without the API it is hacky) Create a new scene this is done by the C++ core of the game engine.
The API can be improve a bridge exist between the C++ core and the API.

I think because there is no real plan and roadmap behind GDevelop. Contributors usually just pick a random thing they find interesting and do it just for fun with no real plans and use cases in mind.

True, sadly, that’s why if you have a dev background it will be easier for your to use a lib like suggest @ddabrahim, and/or take a look on the GDevelop repository for get help and add extend the API.

Probably the dev contributed this extension did find a lib to generate noise values and thought it could be interesting to work with and to have it in GD and that’s it really.

The noise extension come from an Add_, he wrote awiki page about it with an example.