Hello.
The following example is a function/blueprint macro used in compare two enum values of different enum types. It use wildcard pins.
Take this function for example. I want to know how to implement wildcard in C++.
Thanks!
Hello.
The following example is a function/blueprint macro used in compare two enum values of different enum types. It use wildcard pins.
Take this function for example. I want to know how to implement wildcard in C++.
Thanks!
You can see how the KismetArray library does it:
\UE_4.26\Engine\Source\Runtime\Engine\Private\KismetArrayLibrary.cpp
.h:
UFUNCTION(BlueprintCallable, CustomThunk, meta=(ArrayParm = "TargetArray", ArrayTypeDependentParams = "NewItem", AutoCreateRefTerm = "NewItem"))
static int32 Array_Add(const TArray<int32>& TargetArray, const int32& NewItem);
.cpp:
int32 UKismetArrayLibrary::GenericArray_Add(void* TargetArray, const FArrayProperty* ArrayProp, const void* NewItem)
{
int32 NewIndex = INDEX_NONE;
if( TargetArray )
{
FScriptArrayHelper ArrayHelper(ArrayProp, TargetArray);
FProperty* InnerProp = ArrayProp->Inner;
NewIndex = ArrayHelper.AddValue();
InnerProp->CopySingleValueToScriptVM(ArrayHelper.GetRawPtr(NewIndex), NewItem);
}
return NewIndex;
}
The important word here is CustomThunk in the UFUNCTION.
Thank you for your answer, Seda145.
You gave me an example of implementing a function return wildcard Array. Besides, I want to know how to implement a function with wildcard type input/output pins like the example above, not the array.
Do you know anything about it? I referred to the document but only found CustomThunk needs DECLARE_FUNTION. I did not find how to use DECLARE_FUNTION in the document.
Would you please give me a C++ version of the example shown in my image above?
Thank you again sincerely for your answer!
Three things:
First, while Seda145’s example is how arrays work I don’t think I’ve every seen a similar mechanism for doing wildcards in C++ that way with anything except arrays. Arrays are sort of a special case that have additional type information that a naked variable wouldn’t have. The only way I’ve seen wildcards truly done in C++ is through custom K2Node implementations which are like fancy macros.
Second, are you sure that does what you think it does? Whenever I’ve used wildcards the moment one wildcard is given a type, that type is assigned to all the other wildcards. So your example of comparing enumerations of different types shouldn’t work. It may look like it there but not when you try to actually use it.
Third, it’s generally not a good practice to be comparing values across enumerations. Definitely not in a generic fashion like this. It might make sense for some specific pair of enumerations, but in that case you write a function that can take one of each and not wildcards.
I agree, I missed the part that it is about enum comparison. The only case I actually found Wildcard pins useful is when working with struct types of which the type is not immediately clear (datatable operation macros). For anything else I wouldn’t bother really.
It’s been a while since I read about CustomThunks and I can not find the c++ example I had in mind on how to deal with the memory, afaik you had to implement something complex yourself to handle the inputs properly.
I had a case before where I could not expose an enum to BP without modifying engine source code (which I avoid) so I created a new enum, exposed to BP, with only the values that were going to be implemented. So, a comparison had to be done at certain points.
I created a switch in c++ to do a comparison between the two:
// EnumA
// EnumB
// InEnumValueA
// InEnumValueB
switch(InEnumValueA) {
case (EnumA::ValueA):
if (InEnumValueB == EnumB::ValueA) {
// DoSomething
}
break;
// case .....
}
Oh yeah, most definitely. I’ve had cases where I’ve got an enumeration in my own code but for whatever reason Blueprint needs a unique version of it in some way that needs to be comparable to the non-blueprint enum. But that all comes back to my caveat that it might be okay for specific pairs of enumerations, but not for the general case of any pair of enumeration types.