Struct alternative?

I had a struct which had members of the type of other structs. The problem with structs in blueprints is that they can not be passed by reference in any way (unless you use C++ but even there it’s tricky).

So I was like okay. I just make a blueprint with Object as it’s parent and put a bunch of global variables in there to replace the structs. However, there is no construction-script and I can’t construct a new blueprint as the default value for variables. I don’t want to set it’s parent to Actor because the it will spawn an actual object in the world.

So basically I can use blueprints to substitute structs. But the moment I need a substitute for structs that have other structs as their variable types, is not possible without using C++?

Maybe some form of data-only-instanced-blueprints?

Have you considered Data tables?

I would love an answer to this. I really don’t understand how Epic can’t see how big of a problem not being able to pass a struct by pointer really is.

If I wanted an array of inherited data types I’m forced to write my own type from uobject, write custom replication code, and use it as a wrapper class for the structs. How is this acceptable design? Instead of having one hierarchy of structures I’m forced to have a hierarchy of wrapper classes to go along with it.

The ability to use structures with spreadsheets is too valuable to drop structures completely, but to use inherited structures you have to dance through hoops.

I really don’t understand.

You can’t use pointers with structures if you’re to use the UPROPERTY marco. Because I need replication and expose on spawn, having the pointer a UPROPERTY is required.

I need to use an array of struct pointers to support inheritance, but you can only pass by value when using structures. I see I’m in the BP section, so I probably should’ve described what I wrote above in BP terms. But the point is exactly the same - structures can only be passed by value.

Data Tables are actual tables and thus unusable for this. They use rows and such. A struct and a table are totally different.

Hm, you can change existing struct variable by ref with Set members node.
Is that what you’re looking for or I misunderstood something?

What’s the issue with not being able to pass by reference? What is it preventing you from doing?

In your example you have a direct reference to the struct. For this simple case yes it will work. But I rarely have such a simple case.

The problem for me occurs when I have an array of structs in some child blueprint really deeply nested and then I have a function that retrieves such a struct based on certain conditions. The problem is that this function, can not pass it by reference in blueprints (only in C++). So I can not use any kind of function to retrieve them if I later want to change their vale(s). Not to mention that I often accidentally do this and then while debugging I’m like “ohyeah… struct + blueprint”…

And if in the above example the struct has variables of type then it becomes undoable to not use functions to retrieve them from other objects.

Also I can not store them in temporal-variables and such (unless I only need to read their values) because this creates a copy of the struct. There is no way of getting/storing it by reference in blueprints that I’m aware of. Another problem:

Example: Player has a struct with a variable ammo.
Every frame I want to reduce the amount of ammo in this struct by 1 (but only if the player still uses that weapon). Normally when switching weapons I would store the active-ammo-struct in the player and then I could just subtract it by 1 every frame. But because I can’t store a reference to a struct, I’m forced to loop through all the ammo-structs the player has, find the one matching the active-weapon and then use set-members-in-struct, every frame! Which is bad for performance.

The only workaround that I know of is using C++ and creating classes that store only a bunch of variables (which is dirty) but I don’t really know any other way right now. Because then I can use pointers and/or pass by reference.

Okay, I just noticed that you can pass structs to functions by ref, as well as other types, but can’t set function output by ref, as well as other types. So it’s not strictly a struct problem(Of course it is not the case for actors which passed by ref by default)

I have same situation as you and I store only index of a struct I want to modify later and above mentioned Set Members in function to modify it by ref.

Edit for example:
Yeah, you can just store index of struct in array to avoid constant looping through the array to find the one you want

Yeah it’s true it can be made to work with blueprints. And again it works in simple cases where you can just store an integer value so you know what index it’s stored in.

But when it get’s even slightly more complex and you also need a reference to the object that contains the struct (if it’s stored in another object):

  1. You gotta store a reference to the object containing your struct(s)
  2. You gotta store an integer that points to the index of the struct in the array
  3. Etc.
  4. You gotta write several blueprint nodes EVERY TIME (hopefully it can be macro-ed) to retrieve the values.
  5. You probably end up writing a struct to retrieve your struct. It will contain the variables mentioned in step 1 to 3.

So yes it is technically possible without using C++ okay. But it’s so extremely dirty and such a massive pain to maintain later on… I don’t see it work. I mean, you may even end up writing extra structs just so you can retrieve the struct you want because… no pass by reference… I believe this is what Asusralis meant.

Because I can not believe that everyone jumps through so many loops to get it to work, either everyone is using C++ or there must be another solution that we are not aware of.

I’m not arguing with that - simple ref would be much more convenient, clean and easier to use. Probably it’s time to create a request in feedback section :smiley:

Yes I know but they use structs and I thought that’s the better way to go than what you’re trying to describe. Good luck.

It’s even worse: Struct setmember not working - Blueprint - Unreal Engine Forums

Seems we are also not allowed to use structs in arrays because that is bugged since at least UE4.4…

You can absolutely pass structs in a reference…

There’s nothing (that comes to mind right away) that you CAN’T pass as a reference… A reference is just a reference, there’s no limit in Blueprints to what you can reference…

I use references to structs quite a bit in the game I’m currently working on. In fact it’s extremely common with systems like inventory management. You have to get a struct from the item being dragged, dropped etc…

You CAN do it in Blueprints. In fact there’s multiple ways to do this. Message me and I can give you a few ways to do what you’re trying to do.

That may be the case now but 5 years ago when I asked this question it was probably different…

That’s possible. I didn’t realize when this was posted til after I sent my answer lol. I apologize.