Download

Better off with a struct or a class?

I’m porting some level generation code over to unreal, and originally my level data was held in a structure. But the more I seem to be reading through the Unreal docs and getting familiar with coding in unreal, I’m wondering if I would be better off making my level data a class instead of a structure.

In the most simplistic terms, my level generator can be thought of as a simple maze generator (though, this is only the base functionality and the data will be used to create more complex geometry than simply mazes, but the theory is the same.)

My original thought (and indeed my original code) was to create a structure to hold the level data, and have that be a member of a class to populate, create, and manipulate the array of structures.

The structure array will need to be accessible via blueprints for manipulation and rendering the level components.

I just need to know from someone with a little more experience with C++ in Unreal and all the quirks and connections so that I don’t accidentally have my little Peking butterfly create a hurricane in Central Park. (If you get my meaning…)

Thank you!

I think I’ve managed to answer my own question and I’m going with a struct. But I’d still appreciate any thoughts on this. I’m pretty sure I’ve got a good grasp of what I need to do to expose everything to blueprints, but if there are any tricky pitfalls anyone has run into, I’d love to hear about them so I can be prepared.

I’ve got my structure created, and I’m creating a TArray<FGridTile> LevelTiles; to store the data. On the right path so far?