Blueprint member vars Reference to Struct?

I noticed there’s no way to store a reference to a struct in a blueprint property? Only as function parameters?

I was hoping to store a reference to a specific struct like you would in C++ rather than copying the data of the entire struct.

Structs are a pain in blueprints. As an experienced developer I will always advise to use Blueprints for quick Prototyping and c++ for anything else. In blueprints you have the “Set members” node to set properties on a struct directly but most of the time you will be copy pasting that node all over just to replicate a c++ oneliner.

I normally do that too, but this is specifically a UI style related thing that I thought would be one of the few cases it’s easier to do things in blueprint than C++.

I was basically trying to store a reference to a struct that defines a bunch of properties about how UI should be styled. You can customize your UI’s color scheme from the options menu, and also makes it easier to develop since it’s easy to tweak colors from one place like you would with CSS. It would be quite a lot of data to “Copy” instead of keeping as a reference, but also a pain to do from C++ since it’s more art side stuff. And there’s already a data asset wrapping a bunch of structs, just wanted to reference a specific property within the data asset.

I am not entirely sure what you are trying to do but I am a 100% sure that comparing CSS to UE4’s UI system will suck. I am a fullstack web and game developer and I am currently writing documentation about best practices in widget development.

One of my rules is: don’t mix up code with design. In UE this is rather impossible to do.

Take for example a custom button (UserWidget) for which you have to define a style (as designer) for different states of the button (normal / hovered / visited / disabled). The editor panel won’t let you do this. The easiest way to deal with this is to both design and program. It would be messy to define custom structs all these states meant to style the widget with, since usually we also want to carefully design widget animation transitions, editor supported “WYSIWYG” or even custom logic.

Sometimes it helps to create an abstract base class in BP or (please do c++) which will contain all the base logic, from which BP UserWidgets will derive just so the designer can implement the styles per UAsset. Perhaps it is best to let the designer implement the styles based on states (hovered / visited) through an widget animation. Having a struct to define basic parameters such as colors is rather… limited… at best.

Yeah that is roughly what I have set up too, and CSS is a very loose description.

It’s more to support something like what DooM Eternal has with custom UI color pallettes. My button code, for example, would pass to its dynamic material instance, whatever color is currently set for some state in the style struct. And it’s not trying to be some super complicated system either, just a collection of structs with a few color and float values to define glow intensity or colors or whatnot, and it all blends together depending on the interaction state.

The styles are in fact all pretty much set up in the UMG widget, but the colors can swap out depending on what the current player has set. And if there’s split screen, each player actually would have their own color, so I didn’t end up using global material params.

I did kindof manage to set up something a little different, and may even rewrite this in C++ later to be more performant. Right now it’s still heavily in flux and from the artist side it’s easier to add new properties to blueprint structs on the fly than to do it in C++.

Yeah, you can’t, but you can use a UObject instead of a struct. Its overhead is not so heavy that you can’t have thousands of data-only UObjects to be honest. If you want to keep it as a struct for whatever reason, you can also create a UObject that has the struct as a member, then pass around the object pointer to reference the original struct on that UObject. No struct copies!

1 Like