eldany.uy
(eldany.uy)
January 31, 2022, 11:10am
1
hi! I am async loading some assets and I want to use a delegate function with parameters but
FlatentActionInfo looks like this:
FLatentActionInfo info;
info.CallbackTarget = this;
info.ExecutionFunction = "myLoadInc";
info.Linkage = 0;
how can I call a delegate function with parameters?
I want to call
myLoadInc(FName Item)
instead just
myLoadInc();
Thanks!!
Dany
1 Like
Natalo77
(Natalo77)
January 31, 2022, 11:13am
2
Can you show the context and code within which your attempt is?
eldany.uy
(eldany.uy)
January 31, 2022, 11:21am
3
void ALevel_Main_CPP::myAssetsLoader()
{
TArray<FName> Levels = {"MENU","Roulette","Factory", "Train", "Learned"};
FLatentActionInfo info;
info.CallbackTarget = this;
info.ExecutionFunction = "myLoadInc(thisName)"; /// I want to call myLoadInc using public thisName
info.Linkage = 0;
int32 UUID = 1000;
for ( auto &level : Levels )
{
info.UUID = UUID;
UGameplayStatics::LoadStreamLevel(this,level,false,false,info);
thisName = level.ToString(); ///this name is public
UUID++;
}
}
void ALevel_Main_CPP::myLoadInc(FString levelName)
{
levelName = "LEVEL - " + levelName + " - LOADED!";
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, levelName);
myLoadCounts++;
if (myLoadCounts == 15) createSkip();
}
eldany.uy
(eldany.uy)
January 31, 2022, 11:43am
4
ummm I think what I want to do is not possible in a simple way as this is an async proccess, name of the variable will change (actually will always show the last one because would run all LoadStreamLevel lines before the first myLoadInc callback.
Natalo77
(Natalo77)
January 31, 2022, 2:14pm
5
I’ve been looking through the code for this for a while, and I’ve gotta say, I have no freaking idea.
1 Like
bump, still nothing on whole of internet answering the question
my current hack to fix this problem:
check how your latent calls its complete function, for me im doing FStreamLevelAction and when its done it calls Response.FinishAndTriggerIf(true, LatentInfo.ExecutionFunction, LatentInfo.Linkage, LatentInfo.CallbackTarget);
which means all i have to work with is Linkage, an int32.
so for my callback function it is just OnLevelLoaded(int32 Linkage)
i construct my latent info:
FLatentActionInfo LatentInfo;
LatentInfo.CallbackTarget = this;
static const FName OnLevelLoaded = TEXT("OnLevelLoaded");
LatentInfo.ExecutionFunction = OnLevelLoaded;
LatentInfo.UUID = NewPlayer->GetUniqueID();
LatentInfo.Linkage = LatentInfo.UUID;
I pair Linkage to Newplayer (this is just a tmap<int32, struct> as a global in the class) :
FPlayerLoginLevelRequest PlayerLoginLevelRequest;
PlayerLoginLevelRequest.PC = NewPlayer;
PlayerLoginLevelRequest.LevelName = MapName;
PlayersLoggingIn.Add(LatentInfo.UUID, PlayerLoginLevelRequest);
Then i fire off the latent function…
Now when the latent is finished it calls this:
void AArkWelderGameMode::OnLevelLoaded(int32 Linkage)
{
const FPlayerLoginLevelRequest& PlayerLoginLevelRequest = PlayersLoggingIn.FindChecked(Linkage);
//do stuff
PlayersLoggingIn.Remove(Linkage);
}
and thats how i transfer “arguments” to latent action callback
really ugly but idk what else to do