I need operator+-*/ blueprint struct. blueprint struct is not enough to be a complete programmable type

Now my solution is like this, but it is not convenient to call native types.this function`s class is inherit blueprintfunctionlibrary.If struct has a blueprint graph to operator it It will be more convenient than now.

1 Like

Seems like it’s possible in a way:
Expose struct operators to Blueprint - Editor Scripting - Unreal Engine Forums .

Of course you would have to define the operator node in C++.
But maybe it’s possible to do this in a generic way using Unreal reflection.

Unreal Property System (Reflection) - Unreal Engine.

It must declare the struct in cpp, I dont want to declare a cpp struct because if i changed cpp code such as make a new element in struct, the variable in blueprint will miss its struct class.the blueprint function like break will spoil. In development I cant think about how much elements in this struct when declare the struct.
After declare the struct, even this struct variable are frequently defined everywhere in the game, and many calculations are maked, I may modify the elements inside the struct as needed. If cpp struct is used, it means that large-area program exceptions will be caused. The blueprint struct will not have so many problems in subsequent modifications.

Of course, if the whole game does not use blueprints and only uses cpp development, there will be no problem that the struct element can not be modified as I mentioned above. However, it is not a wise choice to declare a cpp struct variable in the blueprint.

Ok. I see your problem.

I googled a little bit more and it seems that you can actually make a blueprint node that accepts any (generic) struct and then operates on it using reflection:

So maybe you could make a generic ADD node that checks its two inputs if they are the same type and adds them if possible?

Not sure about the type of a return value of such node, that would probably not be possible to make in a generic way. But as a workaround you could accept your struct parameters as Ref and modify them directly instead of returning a new instance which would be what you’d expect from a normal ADD node.

Or build a “AddMyStruct” function (maybe in a blueprint function library) that adds the structs.
On the inside of that function, you need to break, add, and re-assembly the struct, but that’s typically what your C++ code would do, too.
And any user just calls the AddMyStruct node, passing in the two instances. The fact that it’s not literally called “+” shouldn’t be a big hinderance.

This is what I did. problem is if there are many struct, the calculation function I make for each struct will fill my right-mouse menu. I need to find the calculation function of the current struct from many functions.

I’ll try, but it doesn’t seem simpler than my current practice.

Why wouldn’t an “operator +” fill the menu just as much?
Also, I’ve found that using categories can help clean up the menu.
Then again, I typically right-click and then type some bits of the function I know I want (such as the data type,) so I don’t generally care how “big” the menu is before filtering.