I’m trying to make a system where when the player overlaps an actor, a widget appears with the name of a level that is specified in the instance of the actor that the player is overlapping. Then they can use an action key to enter that world.
So I have the problem where the name of what needs to be displayed in the widget as well as the FName of the level that needs to be opened are in the specific instance of an actor that the player is overlapping. What I thought of doing was this inside of the player character implementation file:
IInteractInterface* Interface = Cast<IInteractInterface>( );
if (Interface)
{
LevelToOpen = Interface->ReturnLevelToOpen();
}
if (LevelToLoad != "")
{
UGameplayStatics::OpenLevel
(
this,
LevelToLoad,
false
);
}
Both the player character and the class of the actor that the player needs to overlap with are part of the InteractInterface interface. This code should work but I’m not sure how to get what needs to be put in the blank space on the first line. If my knowledge is correct, it should be a reference to the instance of the actor that the player is overlapping. I already know exactly which actor that should be, but I’m not sure how to get a reference to it. I don’t know how to use GetOverlappingActors() because it would need to be called from an ACharacter (the player) instead of an AActor, meaning that I wouldn’t be able to call it.
Could I just use a reference to the overlapping actor’s class instead of the instance?
Thanks for any help in advance!