Download

Struct best practice

I’m using structures for the majority of my project, and they are new to me. My question focuses largely on efficiency and performance. I wanted to know if there is a best practice for using structs? For every major actor I use there is a struct template associated with it that carries various properties that are later saved in JSON and then upon load they are processed by the project to load the level. They work very well but I want to make sure I’m not getting ahead of myself by putting too many variables into the structs.

For example:
Let’s say you have one struct with 10 variables in one struct with 40 variables. For each case, unreal engine is only looking for one variable within each struct - is either case more CPU intensive than the other?

Can a struct have a large quantity of variables within a board is at a better practice to break them up?

If there is a difference at all, it would be extremely small. Don’t worry about it.

I do not know what a “board” is in the context of structs.

“Within a board” is a Mac dictation error for the word “or” :slight_smile: Thanks

Be forewarned: There is a bug (or unexpected methodology) with the way Unreal handles structures.

If you later make a change to the structure, in particular adding a variable, you will need to recompile and save every blueprint that references that structure to be able to cook your project.

This problem is not apparent when working in the editor – a game runs fine in PIE. Only when cooking do the Unknown Structure errors show up.

I recommend to not use structs as serious data containers. Use UObjects instead.
I’d only use them to transfer read-only data, similar to HitResult or Key Structures.

Thank you for the heads-up. I don’t have enough blueprints that this would be a problem but it is good to know.