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.

参考:http://orfeasel.com/creating-a-c-level-blueprint/

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();

Or:

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

Spawn actor in static function:

UWorld* World = GWorld->GetWorld();
World->SpawnActor(ActorClass);

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