x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Create blueprint asset file with C++

It's perhaps not too difficult to achieve, but right now I don't find the right information concerning this.

I want to create a new blueprint in C++ as part of an importer module within our project, which I'm writing myself. With that I mean creating an actual full blueprint asset file (not just a node or a function etc.), that goes into the editor's asset browser for content creators to use. I want to be able to define the name, superclass and file path of the blueprint in my function.

What I found so far was this:

     FString PackageName = TEXT("/Game/SomePackageLocation/" + name);
     UPackage *Package = CreatePackage(NULL, *PackageName);
 
     UMyAsset *NewAsset = new (Package, FName("MyAsset"), Flags | RF_Public) 
                        UMyAsset(FPostConstructInitializeProperties());
 
     if (NewAsset != NULL)
     {
         // Fill in the assets data here
     }
 
     FAssetRegistryModule::AssetCreated(NewAsset);
     NewAsset->MarkPackageDirty();

I'm don't know how to use this code snipped or what exactly it does (I can only assume it creates an asset) and I also think it's not applicable to what I want to achieve, since I want a blueprint based on a given superclass.

How can I do that?

Product Version: UE 4.19
Tags:
more ▼

asked Jan 08 '19 at 12:04 PM in C++ Programming

avatar image

GenerationLost
6 1 2 3

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

unfortunately u cannot create a uasset file from any external sources. you need to use the editor for this.

more ▼

answered Jan 08 '19 at 12:24 PM

avatar image

Jurrasic Studios
249 3 5 13

avatar image GenerationLost Jan 08 '19 at 12:43 PM

That doesn't seem right. I mean other import plugins achieve the same, that's also what the AssetRegistryModule is for, right?

avatar image Jurrasic Studios Jan 09 '19 at 06:41 PM

hmm maybe im just not understanding it right but if you want to create a Custom Editor Asset use this: https://orfeasel.com/creating-custom-editor-assets/

avatar image GenerationLost Jan 10 '19 at 10:04 AM

That already goes in the right direction. The difference is, that my goal doesn't involve using the editor at the point of blueprint creation. It's all about automation as part of a character import tool chain. The import (JSON data) is invoked in the editor, that's true. After that, data is read, converted and should then automatically create blueprints for each imported character, so each blueprint should simply be based on our character class.

From your link, I'm fixating on this line:

 //Create the editor asset 
 UOrfeasCustomAsset* OrfeasEditorAsset = NewObject<UOrfeasCustomAsset>(InParent, InClass, InName, Flags);

That looks like the function I would need. Does this already create a new asset and then I'd only need to call FAssetRegistryModule::AssetCreated(NewAsset); to have it registered? Unfortunately I can't try right now, so I ask just to be sure up front.

(comments are locked)
10|2000 characters needed characters left

I was able to find a function that may help after digging around in the FKismetEditorUtilities:

    FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools");
     
     FString name = "testBlueprint";
     name = UPackageTools::SanitizePackageName(name);
     name = ObjectTools::SanitizeObjectName(name);
     FName fname = *name;
 
     FString packagePath = "/Game/Test/" + name;
     UPackage* OuterForAsset = CreatePackage(nullptr, *packagePath);
 
     UClass* BlueprintClass = nullptr;
     UClass* BlueprintGeneratedClass = nullptr;
 
     IKismetCompilerInterface& KismetCompilerModule = FModuleManager::LoadModuleChecked<IKismetCompilerInterface>("KismetCompiler");
     KismetCompilerModule.GetBlueprintTypesForClass(YourClassType::StaticClass(), BlueprintClass, BlueprintGeneratedClass);
     UBlueprint* newBlueprint = FKismetEditorUtilities::CreateBlueprint(YourClassType::StaticClass(), OuterForAsset, fname, BPTYPE_Normal, BlueprintClass, BlueprintGeneratedClass, FName("GeneratingBlueprintTest"));
     FAssetRegistryModule::AssetCreated(newBlueprint);
     FAssetEditorManager::Get().OpenEditorForAsset(newBlueprint);

     OuterForAsset->SetDirtyFlag(true);
     TArray<UPackage*> packagesToSave;
     packagesToSave.Add(OuterForAsset);
     FEditorFileUtils::PromptForCheckoutAndSave(packagesToSave, false, false);

For my case this works, it creates the asset, saves it, and opens up the blueprint window in editor upon creation, which is all I need. However, as a warning, I ran in to trouble when I tried to save the asset before opening up the blueprint window in editor.

more ▼

answered Feb 13 '19 at 04:53 PM

avatar image

TastyStock
3 1 2

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question