Comparing Two Void* Parameters (knowing their FProperty), How to do?

Hello,

I have a UFunction that uses two void*. I use “CustomThunk” + “DECLARE_FUNCTION” to be able to handle the “Property” of the incoming variables and references.

My function is comparing whether they are equal or not. However, I would like to get the value of the void* to be able to compare, because at the moment it is checking whether they are exactly the same “variable” instead of checking whether the values of the variables are equal.
Note: I have access to the “FProperty” of each “void*”.

Some tip? Thank you in advance if someone replies.

Sincerely, HighRender.

FProperties & class introspection are specific to UE’s C++ framework. Void pointers are not. In order to introspect you’re gonna have to “come back to the fold” so to speak, coming back to the UE framework. In this case this means finding the UClass of each side of the comparison.

Which means, you need to determine which class is behind each void pointer. I’m 90% sure this is going to end badly since you have multiple candidate classes behind your void pointers.

It seems like you should really consider something other than void pointers. If you really want a void pointer somewhere, you could make a wrapper class/struct of some kind with two properties: A void pointer, and some indication of the class behind the void pointer, that enables you to cast safely.

But in my opinion, since you’re expecting a match in the properties of each object, something akin to an interface or a common abstract parent class would do the trick. Since I don’t believe that UE5’s interfaces officially support properties, maybe a common abstract parent class?

If that’s not possible, then use a UE5 interface. It won’t let you make UPROPERTIES so any property will be unknown to the reflection system, but at the same time, if you cast to the interface class, you don’t need to use UE’s introspection anymore.

Altrue,
Thank you for the reply.

I’ll do some research later on Interfaces. By the way, are interfaces allowed in “Blueprint Function Library” (c++)? (Forgive me if it’s a silly question, lol)

The class of both “void*” are exactly the same. I was thinking about creating a function that would be able to tell if the value of two variables are equal. Like, everything worked except this detail about figuring out how to use “void*” to get its class and do the checking.
Example: Knowing if two integers have the same value. I know you might think that this already exists in blueprints, yes it does, however, “not in a universal way”. Some types of variables do not work in the engine’s “EqualEqual” function (for blueprints).

If you had any ideas on how to adjust this last detail, giving an example, I would be very grateful. If not, perhaps in the distant future. This function would be the best of all. I would be able to make variations of it, which everyone would like. However, at the moment I ended up putting the idea aside and moving on to plan b. Of course, hope always remains, I will wait.

Sincerely, HighRender.

I don’t quite understand what you want, in terms of your example and the last paragraphs of your message.

On the matter of interfaces, I don’t believe that it would pose a problem to use them as types inside Blueprint Function Libraries. However do be mindful that for each interface, you have the IInterface (i interface), and the UInterface. Make sure not to confuse the two when using them in code.

Or maybe you meant to use an Interface on the Blueprint Function Library class itself? But it doesn’t make sense since this class is never instanced. It’s just a way to hold a bunch of UFunctions to make them available in BPs.

FProperty provides function Identical to compare values pointed to by void* pointers.

It might be wise however to first make sure that the types are equal.

Example :

Stack.StepCompiledIn<FProperty>(nullptr);
FProperty* PropA = Stack.MostRecentProperty;
void* ValueA = Stack.MostRecentPropertyAddress;

Stack.StepCompiledIn<FProperty>(nullptr);
FProperty* PropB = Stack.MostRecentProperty;
void* ValueB = Stack.MostRecentPropertyAddress;

if (PropA->SameType(PropB))
{
    if (PropA->Identical(ValueA, ValueB))
    {
        // values are equal
    }
}

Note that this may not play super well with numerical property types.
An FByteProperty and FIntProperty could have the same value on paper, but you cannot use ::Identical on two different property types (hence the SameType check).
If you need to handle that, let me know I’ll cook something up.

Sorry, sometimes is difficult to explain c++ things (I am a beginner hahaha).
Thank you for your time and help until now. I always save valuable tips and answers. You gave me a good ones.

Fortunately, Chatouille answer is correct and directly at the key objective of my function.

1 Like

Thank you very much.
I customized half of your code to my “needs”. The function “executes” only when using the same parameter type.
It is working as expected. However, a problem persists.
If any parameter of the function is invalid (by any reason), the editor will crash instantly.

Is there a way to check if it is valid before the lines “Stack.StepCompiledIn(nullptr);”? The error is precisely in this line. If it is invalid, would it be possible to return an error when compiling “blueprint” in the editor?
Because I already know how to return a message in the Log. However, in the blueprint it would be nice to prevent users from getting the error by leaving the “function input disconnected” (because depending on the type of function, Unreal compiles without alerts).

If you answered that, the function will finally work.

Sincerely, HighRender.