BenPyton / ProceduralDungeon

This is an Unreal Engine 4/5 plugin to generate procedural dungeon.
MIT License
513 stars 61 forks source link

Question about room logic #50

Open GamesAndBacon opened 4 months ago

GamesAndBacon commented 4 months ago

hello there, im wondering about how i could encapsulate room logic.

for example, i have a room and i want it to be a wave attack type room. i have spawner actors placed around and i want the room to know about them and be able to use them. i looked at custom data but i dont think this is what i want.

i currently have another actor my "room manager" that i place in the level blueprint for the room and that does the job. But im wondering would i be better off expanding the room class? perhaps even removing the custom data aproach and just letting the room class have more of a role in managing all logic in that room.

not sure what you would recommend.

BenPyton commented 4 months ago

Hi @GamesAndBacon You're right, RoomCustomData is meant to carry per room instance data. You can have some functions in it if you want to manipulate those data, but you should not have logic inside that have direct impact in the world. Instead, I think the better approach is to make your logic in your room level blueprints.

What I would first try do in your case, would be to create an actor component with the standard logic inside. However, since you can't add components to the level blueprint actor in editor, you should add it at runtime (meaning you can't set per instance variables like in a common actor blueprint class.)

So in short, I would go that way:

If you have a C++ project, you can create a subclass of the Room Level class (the level blueprint specific to the plugin). Inside you can add your component or your logic directly, and then reparent the level blueprints to your own sub-class. In that case you can also add editable variables in the editor (like I've done with the Room Data asset to display boundaries of the room in editor).

GamesAndBacon commented 3 months ago

just as a follow up to this i wanted to let you know which direction i went with.

i created a RoomLogicComponent class in C++, and when the RoomLevel is just about to finish initilizing at the bottom of begin play, i add the component and pass in the room and room data.

i added a helper function for adding a component, and exposed to to BP. so you could add more at runtime if you wanted. maaaybe your map has modifiers and you want them to add features to certain rooms. something along the lines of Path of Exile random enocunters.

i also added a helper function to GetAllActorsInLevel, inside the level instance. just something i found handy so i could check for spawn points, or if all my team members were inside the room at the same time ect. im debating making that purely data orientated though. maybe a struct of GameplayTags and vectors. and just implying what a certain location COULD be, then the logic component could read them and place actors accordingly.

i also exposed the roomlevel returning the dungeongenerator. i use my dungeon generator as a singlular source for where i keep my pooled actors and things. so begin able to easily reach that was handy.

in the end i went with using logic driver pro lol. but now in my roomlogiccomponent thats where i spawn my state machine and plugin all the required data. https://imgur.com/totRpI9