ok, thanks. In my “PlayerListWidget.h” class which is the parent to the player list blueprint widget, I have
UScrollBox* CurrPlayers;
//addedplayer is reference to player BP widget to add to Currplayers scrollbox
UPROPERTY(BlueprintReadWrite, Category = “Widgets”)
TSubclassOf addedplayer;
In MyStarterMenuWidget.h I defined the following:
UPlayerListWidget* MyW;
//wplaylis assigned to player list widget blueprint( widget with just panel and empty scrollbox)
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Widgets”)
TSubclassOf wplaylis;
In MyStarterMenuWidget.cpp (in Join button function I have):
//adds empty playerlist scroll box to screen
void UMyStarterMenuWidget::JoinGame()
{
if (wplaylis) {
MyplayerList= CreateWidget(GetWorld()->GetFirstPlayerController(), wplaylis);
Myplayerlist->AddToViewport();
}
}
In MyGameInstance.h class I have:
UPROPERTY(BlueprintReadWrite, Category = “Widgets”)
TSubclassOf wPlayer;
UPROPERTY( BlueprintReadWrite, Category = “Widgets”)
TSubclassOf wPlayerList;
In my MyGameInstance.cpp I have
void MyGameInstance::OnPlayerAdded(){
//wPlayerlist variable assigned to player list widget blueprint
//wPlayer variable assigned to player widget blueprint
if (wPlayerList && wPlayer) // Check if the Asset is assigned in the blueprint.
{
UPlayerListWidget *playersList = Cast(wPlayerList->GetClass());
player= CreateWidget(GetWorld(), wPlayer);
//add player to Currplayers scrollbox
er->CurrPlayers->AddChild(player);
}
However it throws an error in saying “playersList” in OnPlayerAdded() is NULL. How can I change OnPlayerAdded() so I can make a call to CurrPlayers scrollbox in PlayerListWidget and add “player” child?