I am attempting to make a little bit easier system for calling a cosmetic change on multicast, by networking. For that I am attempting to use a little lambda like so, and having a function ref as an argument:
void RunMulticast(TFunction<void()> Callback);
UFUNCTION(Server, Reliable)
void Server_RunMulticast(TFunction<void()> Callback);
UFUNCTION(NetMulticast, Reliable)
void Multicast_RunMulticast(TFunction<void()> Callback);
and in .cpp:
void AGamePlayerCharacter::RunMulticast(TFunction<void()> Callback)
{
if (IsLocallyControlled())
{
Callback();
}
Server_RunMulticast(Callback);
}
void AGamePlayerCharacter::Server_RunMulticast_Implementation(TFunction<void()> Callback)
{
Multicast_RunMulticast(Callback);
}
void AGamePlayerCharacter::Multicast_RunMulticast_Implementation(TFunction<void()> Callback)
{
if (!IsLocallyControlled())
{
Callback();
}
}
Calling the function:
RunMulticast([this]
{
...
});
However, no matter what I do the compiler says:
Unable to find 'class', 'delegate', 'enum', or 'struct' with name 'TFunction'
In the header declarations for the two networking UFUNCTIONs.
Upon looking online a little, this appears to mean that TFunction is not supported in UFUNCTIONs. If I try the basic C++ std::function<void()> I sadly get the same error…
If there are any alternatives to pass a function ref, that would be very appreciated!