UE4 代码创建蓝图类Asset

// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;

public class MyProjectEditor : ModuleRules
{
    
    
	public MyProjectEditor(ReadOnlyTargetRules Target) : base(Target)
	{
    
    
		PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

		PublicDependencyModuleNames.AddRange(new string[] {
    
     "Core", "CoreUObject", "Engine", "InputCore", "MyProject"});

		PrivateDependencyModuleNames.AddRange(new string[]
		{
    
    
			"AssetRegistry", "UnrealEd", "GameProjectGeneration", "ContentBrowser",
		});

// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");

// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
}

template<class NewObjC = UObject>
NewObjC* DoTaskGenerate(const FString& BPName, UPackage* Package, IAssetRegistry& AssetRegistry)
{
    
    
	UBlueprint* NewBP = FKismetEditorUtilities::CreateBlueprint(const_cast<UClass*>(NewObjC::StaticClass()),
		Package, FName(*BPName), BPTYPE_Normal, UBlueprint::StaticClass(), UBlueprintGeneratedClass::StaticClass());

	if (NewBP == nullptr)
		return nullptr;

	NewObjC* TaskObj = Cast<NewObjC>(NewBP->GeneratedClass->GetDefaultObject());

	///
	///set bp default value
	///
	
	// Notify the asset registry
	FAssetRegistryModule::AssetCreated(NewBP);
	// Mark the package dirty...
	Package->MarkPackageDirty();
	// Sync the content browser to the new asset
	TArray<UObject*> SyncAssets;
	SyncAssets.Add(NewBP);
	FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
	ContentBrowserModule.Get().SyncBrowserToAssets(SyncAssets);

	return TaskObj;
}

猜你喜欢

转载自blog.csdn.net/t1370620378/article/details/128192601