Skip to content

Adding Blueprint Static Analysis Tool#

The easiest way to augment the compiler would be to write a UBlueprintCompilerExtension, just derive from that type and when you want to enable your extension (e.g. only when a commandlet is running, ini setting is set, or unconditionally at CDO creation time) just call FBlueprintCompilationManager::RegisterCompilerExtension. The first parameter is the type of blueprints you're interested in - e.g. UBlueprint::StaticClass() if you want to instrument all blueprint compilation.

Reference https://udn.unrealengine.com/questions/513017/blueprint-static-analysis.html

Adding Mapcheck for Blueprints#

Check KismetEditorUtilities.h/BlueprintEditorUtils.h/BlueprintEditorUtils.cpp/ComponentEditorUtils.h

GetSimpleConstructionScript(USceneComponent const* Component);

FindCorrespondingSCSNode(USceneComponent const* ComponentObj);

virtual void EditorReplacedActor(AActor* OldActor) {}

Useful editor tool class:

FBlueprintEditorUtils

===========================================

C++
void UBlueprint::GetAllGraphs(TArray<UEdGraph\*>> Graphs) const

/\*\* Set of pages that combine into a single uber-graph \*/

 UPROPERTY()

 TArray<class UEdGraph\*> UbergraphPages;

 /\*\* Set of functions implemented for this class graphically \*/

 UPROPERTY()

 TArray<class UEdGraph\*> FunctionGraphs;

 /\*\* Graphs of signatures for delegates \*/

 UPROPERTY()

 TArray<class UEdGraph\*> DelegateSignatureGraphs;

 /\*\* Set of macros implemented for this class \*/

 UPROPERTY()

 TArray<class UEdGraph\*> MacroGraphs;

for (UEdGraph\* CurrentGraph : Blueprint->FunctionGraphs)

 {

 if( CurrentGraph->GetFName() == Schema->FN_UserConstructionScript )
 {

 return CurrentGraph;

 }

 }

=========

Find references function/find function

C++
GetFindReferenceSearchString

FindInBlueprints.h:

SFindInBlueprints::MakeSearchQuery() - to comprehensively search blueprint nodes (e.g. parameters, comments, etc)

TSharedPtr< FImaginaryBlueprint> ImaginaryBlueprint(new FImaginaryBlueprint(Blueprint->GetName(), Blueprint->GetPathName(), ParentClass, Interfaces, FFindInBlueprintSearchManager::Get().QuerySingleBlueprint(Blueprint)));

 TSharedPtr< FFiBSearchInstance > SearchInstance(new FFiBSearchInstance);

 FSearchResult SearchResult = RootSearchResult = SearchInstance->StartSearchQuery(SearchValue, ImaginaryBlueprint);

========

C++
//Show what objects points to this, using the assetregistry

ObjectTools::ShowReferencers()

 RetrieveReferencers( TArray<FReferencerInformation>\* OutInternalReferencers, TArray<FReferencerInformation>\* OutExternalReferencers);

//Show objects this points to

ObjectTools::ShowReferencedObjs(GetBlueprintObj());

 //To differentiate between what the default class points to vs. the instance

 ObjectTools::ShowReferencedObjs(GetBlueprintObj()->GeneratedClass);

/\*\* Gather all bps that Blueprint depends on \*/

static void GatherDependencies(const UBlueprint\* Blueprint, TSet<TWeakObjectPtr<UBlueprint>>& OutDependencies, TSet<TWeakObjectPtr<UStruct>>& OutUDSDependencies);

/\*\* Returns a list of loaded Blueprints that are dependent on the given Blueprint. \*/

static void GetDependentBlueprints(UBlueprint\* Blueprint, TArray<UBlueprint\*>& DependentBlueprints, bool bRemoveSelf = true);

=========
Search Asset Registry

C++
FAssetRegistryModule\* AssetRegistryModule = &FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));

TArray<FAssetData> AssetData;

FARFilter Filter;

Filter.ClassNames.Add( UBlueprint::StaticClass()->GetFName() ); //get blueprints

Filter.PackagePaths.Add("/Game/Blueprints/RoomModel"); //from location

AssetRegistryModule->Get().GetAssets(Filter, AssetData);

//AssetRegistryModule->Get().GetAssetsByClass(Class->GetFName(), AssetData);

for (TArray<FAssetData>::TConstIterator PkgIter = AssetData.CreateConstIterator(); PkgIter; ++PkgIter)

{

FAssetData Asset = \*PkgIter;

UBlueprint\* BlueAsset = Cast<UBlueprint>(Asset.GetAsset());

if (BlueAsset->ParentClass == ARoomConnection::StaticClass()){

GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, Asset.AssetName.GetPlainNameString());

}

}

================================

Check if Actor is a Blueprint

C++
UBlueprint::GetBlueprintFromClass(const UClass\* InClass);

BlueprintClass->HasAnyClassFlags(CLASS_CompiledFromBlueprint)

UObject->IsA(UBlueprintGeneratedClass::StaticClass())

UClass->IsChildOf(UBlueprintGeneratedClass::StaticClass())

Find all nodes of type

TArray<UK2Node_CustomEvent\*> BpCustomEvents;

FBlueprintEditorUtils::GetAllNodesOfClass<UK2Node_CustomEvent>(FuncBlueprint, BpCustomEvents);

static bool GetBlueprintHierarchyFromClass(const UClass\* InClass, TArray<UBlueprint\*>& OutBlueprintParents);

===============

For finding shit that exists in bad folders:

C++
TFindObjectReferencers

ShowReferencedObjs

UObject::OutputReferencers()/RetrieveReferencers()