Adding new components based on property change in Editor(Not @ Runtime)

Hello everyone!

Details :

I have been creating a class (Derived from APawn) in C++ that I would like to expose to Blueprints (So Artist/Designers can more easily modify and create assets). Creating a derived Blueprint from the C++ class is easy enough, however I would like some variables and arrays to be populated by changes made when editing the blueprint, also it would be preferable to have new objects and components dynamically added based on said changes.

I’ve looked into:

  • The Constructor – (Useful for adding new components, but no properties are reliably initialized to create said components)
  • PostEditChangeProperty – (Was added to both the Actor class & a custom USkeletalMeshComponent class, never successful in getting it to execute.)
  • PostInitializeComponents – (executes at run-time and not in editor)

Appropriate reference links:

An example:

  • I have multiple skeletal meshes flush with sockets and bones, which will be used to spawn weapons, cameras, sound sources, effects, thrusters, etc… (essentially a base mesh & rig for a modular vehicle).
  • The goal is to retrieve an array of all bone names for the skeletal mesh and save that to a TArray of FNames while in the editor (NOT @ runtime).
  • When a USkeletalMeshComponent were to have it’s SkeletalMesh field set, I would need a way to access that new Mesh reference and call GetBoneNames().
  • Then it would be preferable to be able to create new components for certain bones/sockets.

I’ve gotten partially there (I think), I came across this : [Setting Internal actor properties in editor][1].
Which lead me to the following:

  • PostLoad()
  • PostRegisterAllComponents()

These only seem to work when the actor is placed in the level, in addition it only seems to fire once. I created a quick workaround BlueprintCallable UFUNCTION in the C++ class that manually calls RegisterAllComponents(), and attached that to the constructor graph in the Blueprint class editor. This seems to update the arrays correctly for the actor placed in the level.

Detailed Below:

Header relevant code:

	virtual void PostLoad() override;
	virtual void PostRegisterAllComponents() override;

	//Called by blueprint constructor to refresh the components.
	UFUNCTION(BlueprintCallable, Category = SFIEditorFunctions)
		void RefreshComponents();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

CPP relevant code:

void ASFIShipCore::RefreshComponents()

void ASFIShipCore::PostRegisterAllComponents()
	if (ShipBaseMesh->SkeletalMesh)
		ShipBaseMeshSockets = ShipBaseMesh->GetAllSocketNames();
	if (ShipCockpitMesh->SkeletalMesh)
		ShipCockpitMeshSockets = ShipCockpitMesh->GetAllSocketNames();

Class blueprint


I apologize for the very long-winded explanation, and if more information is needed I will happily provide it.
To summarize what i’m asking:

  1. Is it possible to have Uproperties update in the Blueprint Class Editor realtime?
  2. If so, can those properties be used to create and attach new components in the Blueprint Class Editor?

!Note : I have tried using NewObject() & AddComponent() in both the PostRegistertAllComponents() & OnConstruction(), to no avail.

I appreciate the time anyone has taken to read the above!


Have you tried AActor::OnConstruction | Unreal Engine Documentation

It’s the C++ closest equivalent of the Construction Script for Blueprints. It get’s called every time a change happens.

For dragging an object in the world using the transform gizmo, PostEditMoved get’s called and OnConstruction get’s called only for blueprints that have bRunConstructionScriptOnDrag set to true, but you can overwrite it.