Update object's default values manually?

I have a class that has the following two variables:

#if WITH_EDITORONLY_DATA
	UPROPERTY(BlueprintReadOnly, EditAnywhere)
	USceneComponent* GoblinTransformNode;
#endif

	UPROPERTY(BlueprintReadOnly, EditAnywhere)
	FTransform GoblinTransform;

I’ve bound a function to the node’s TransformUpdated event, ala

GoblinTransformNode->TransformUpdated.AddUObject(this, &AHorde::GoblinTransformUpdate);

What I want is that when GoblinTransformUpdate runs, it copies the transform from GoblinTransformNode to GoblinTransform… permanently? So that a release build will still use that transform instead of the default?

Hi Inconceivable,

If it’s just for that one instance - add a “actor->Modify()” before changing it.

If you want to change the actual Object:

You can enumerate through the classes BP nodes to find the component you want to change (assuming you’re class is based on a class supporting it).
Here’s some code that finds the component you’re looking for: (bp is your loaded class, something like UBlueprint* bp=FindObject(package,*name,true); for loading or a reference to your object there in the code cast to UBlueprint)

FCompilerResultsLog resultsLog;

AActor* bpActor=(AActor*)bp->GeneratedClass->GetDefaultObject();
UBlueprintGeneratedClass* bpClass=Cast<UBlueprintGeneratedClass>(bp->GeneratedClass);
USCS_Node* smcNode=nullptr;
UStaticMeshComponent* smc=nullptr;

// Find the first Scene Component (here, change it to search your specific object)
if(USimpleConstructionScript* sConScript=bpClass->SimpleConstructionScript) {
	for(USCS_Node* node:sConScript->GetAllNodes()) {
		if(auto comp=Cast<USceneComponent>(node->ComponentTemplate)) {
			smcNode=node;
			smc=comp;
			break;
		}
	}
}

if(smc) {
	smc->SetRelativeTransform(transform);
	 FKismetEditorUtilities::CompileBlueprint(bp,EBlueprintCompileOptions::None,&resultsLog);
	FAssetRegistryModule::AssetCreated(bp);
}

1 Like

Great! Thanks!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.