🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Level generation in Unreal Engine 4

Started by
7 comments, last by wessamfathi 6 years, 4 months ago

Hello, I'm trying to design a maze using a mix of procedural and manual generation. I have the maze already generated and would like to place other objects in the maze. The issue is the maze object is created on BeginPlay and so I'm unable to view it in the Editor itself while dragging the object to the Outliner. Any suggestions?

I'm thinking of doing something in the Construction Script or the object Constructor but not not sure if that would be the way to go.

I'm still getting familiar with the Engine code base and only have a little experience in Maya or Blender since I'm a programmer.

Advertisement

Running blueprints in the editor is considered advanced, so they kept it as experimental for a long time; don't know if it still is in 4.18; I am still using 4.15.

Editor Preference  -> Experimental -> Editor Utility Blueprints.(Blutility). You can then either create a custom even for it or use the new class it reveals.

 

Experimental!

So why it is marked as Experimental is because of how things work in the editor isn't the same as in game. For example deleting a object. The safe way to delete a object in the editor is to select it and to press delete.

Don't use the Actor Destroy function! C++ doesn't cleanup automatically and if you don't know what your doing it's going to lead to memory leaks and a whole bunch of other problems.

The safe way to delete your level is to spawn all the objects as child objects of an empty object. That way you only have to find one object in the editor to delete the whole level when your not happy with the generated result.

 

If you use C++ instead of blueprints you can directly change the editor and won't need these extra steps; unless your new to C++ then using the blueprint tool is safer.

 

I hope this helps.

Yup its there in 4.18 as well. This seems to be very useful and a nice place to start. Thank you so much!

I didn't understand what you meant by directly changing the editor. Do you mean to change the editor code?

3 minutes ago, RJSkywalker said:

I didn't understand what you meant by directly changing the editor. Do you mean to change the editor code?

C++ users can mod the engine. Because the source code is free they can also go view it to find how the editor spawns objects. At that point it's just putting the two together and they can make a tool for Unreal that spawns objects in the editor.

 

I just glanced at the question and didn't see you asked about it. The construct script does allow the code to run safely in the editor.

I always assume anyone using Unreal also watched the Blueprint Essential series, it explains how the blueprints where designed to work. If you missed them you should really go take a look, they are very well made.

https://wiki.unrealengine.com/Blueprint_Essentials_-_10_-_Using_Loops:_Procedural_Level_Design

That shows how to use the construct script for procedural design. Sorry for missing that.

39 minutes ago, Scouting Ninja said:

C++ users can mod the engine. Because the source code is free they can also go view it to find how the editor spawns objects. At that point it's just putting the two together and they can make a tool for Unreal that spawns objects in the editor.

Ohh you meant this way! Yeah that would definitely be one way.

42 minutes ago, Scouting Ninja said:

I always assume anyone using Unreal also watched the Blueprint Essential series, it explains how the blueprints where designed to work. If you missed them you should really go take a look, they are very well made.

Yes I did watch it but I had been trying to use more C++ than Blueprints. But the Blutility tool you mentioned just did my job.

I'm guessing I could generate a level procedurally and bring it up in the Editor using this tool and save the actors generated in my map?

The only thing I'd need to be careful about would be the object destruction like you mentioned.

30 minutes ago, RJSkywalker said:

I'm guessing I could generate a level procedurally and bring it up in the Editor using this tool and save the actors generated in my map?

Yes.

If you write a save function that records the positions of objects, you could also use Unreal's "Simulate" mode to use your generated content.

The Simulate mode plays your game and allows you to use the editor at the same time. So all you would need to do is save that state; because once you stop the game it will revert back.

 

There is millions of ways to do this. The simulation mode would be the easy way because all you would need to do is make a save function; write the positions and objects to a text file and allow your game to read that. 

Perfect!! Thanks a lot! I'll definitely check this out as well! 

Using the BP construction script would be your best bet for generating things in the editor, but note that for your shipped (cooked) builds there are no construction scripts to run anymore, they run once during cooking and that's it.

If you add C++ code in a UObject-based class constructor make sure you only do heavy work within a -


if (!IsTemplate())

- block, otherwise it could affect your loading times negatively.

This topic is closed to new replies.

Advertisement