首先你需要有UE4源码,我用的是4.27
1.添加一个继承于UObject的c++类
我是重写了源码的函数代码:
具体如下:
//.h
UFUNCTION(BlueprintCallable, Category = “EditorUtils”)
static void ToggleImmersiveOnActiveLevelViewport();
//cpp
void UEditorUtils::ToggleImmersiveOnActiveLevelViewport()
{
FLevelEditorModule& AssetRegistryModule = FModuleManager::LoadModuleChecked(TEXT(“LevelEditor”));
TSharedPtr< IAssetViewport > ActiveLevelViewport = AssetRegistryModule.GetFirstActiveViewport();
/UEditorEngine::///FLevelEditorModule::GetFirstActiveViewport();
if (ActiveLevelViewport.IsValid())
{
const bool bAllowAnimation = true;
ActiveLevelViewport->MakeImmersive(!ActiveLevelViewport->IsImmersive(), bAllowAnimation);
}
}
写完之后就可以去编辑器里面调用了