keywords: [UE4]Level Native API Notes

How to let Level Blueprint inherit customized C++ class
  1. New a C++ Actor which inheriting LevelScriptActor.

  2. Open Level Blueprint, then click Class Settings, change Parent Class.

  3. Then you can invoke the customized functions such as UFUNCTION(BlueprintCallable) which defined in your LevelScriptActor class.


How to get LevelScriptActor which an Actor stayed
if (ULevel* Level = MyActor->GetLevel())
    if(ALevelScriptActor* LevelScriptActor = Level->GetLevelScriptActor())
        if (AMyLevelScriptActor* LevelActor = Cast<AMyLevelScriptActor>(LevelScriptActor))
How to get Level name which an Actor stayed
FString LevelName = GetLevel()->GetOuter()->GetName();


FString LevelName = GWorld->GetLevel(0)->GetOuter()->GetName();
How to get world without WorldContextObject

Spawn actor in static function:

UWorld* World = GWorld->GetWorld();

天之道利而无害,人之道为而不争。 ----《道德经》