Actor with UPoseableMeshComponent does not have a SkeletalMesh inside it's Constructor

Hello,

I tried to get access to the SkeletalMesh during the constructor of a UPoseableMeshComponent (3rd Person Project with Starter Content).

To drag and drop different instances of an Actor with that Component inside the World, I created a blueprint called BP_CustomActor from the C+±Class MyPoseableMeshComponent (for source see below) and set the parent of that BP to AActor (see [Picture01][1]).

Then I tried to drag and drop the SkeletalMesh from the Content folder to the SkeletalMesh of the MyPoseableMeshComponent (indicated by the pink arrow in [Picture02][3]).

Immediately UE called the Constructor of it:

LogSkeletalMesh: Warning:

LogSkeletalMesh: Warning: Inside of
UMyPoseableMeshComponent-Constructor!
LogSkeletalMesh: Warning: Number of
bones: 0

LogSkeletalMesh: Warning:
m_pSkeletalMesh NOT set …

LogSkeletalMesh: Warning: END OF
UMyPoseableMeshComponent
CONSTRUCTOR!!!

It is saying that the SkeletalMesh which is accessible through USkinnedMeshComponent is not being set, although I assigned it through UE-Editor.

What am I doing wrong here?

Although I assigned the SkeletalMesh the membervariables m_pSkeletalMesh and m_pSkeleton aren’t set either during construction. Shouldn’t they get updated to the SkeletalMesh you set in the UE-Editor?


For additional information on the MyPoseableMeshComponent:

:::::::::::::::::: MyPoseableMeshComponent.h ::::::::::::::::::

/**
 *
 */
UCLASS(ClassGroup = Rendering, config = Engine, editinlinenew, meta = (BlueprintSpawnableComponent))
class SKELETONLOGGING_API UMyPoseableMeshComponent
	:
		public UPoseableMeshComponent
{
	GENERATED_BODY()

public:
	UMyPoseableMeshComponent();

	UPROPERTY(VisibleAnywhere, Category = ATEST)
		class USkeleton* m_pSkeleton;

	UPROPERTY(VisibleAnywhere, Category = ATEST)
		class USkeletalMesh* m_pSkeletalMesh;

};

:::::::::::::::::: MyPoseableMeshComponent.h ::::::::::::::::::

#include "MyPoseableMeshComponent.h"
#include "Animation/Skeleton.h"
#include "Engine/SkeletalMesh.h"
#include "Components/SkeletalMeshComponent.h"

UMyPoseableMeshComponent::UMyPoseableMeshComponent()
{ 
	UE_LOG(LogSkeletalMesh, Warning, 
		TEXT("-----------------------------------------------------------"));
	UE_LOG(LogSkeletalMesh, Warning, 
		TEXT("Inside of UMyPoseableMeshComponent-Constructor!"));
	UE_LOG(LogSkeletalMesh, Warning, 
		TEXT("Number of bones: %d"), this->GetNumBones());
	this->SetBoneRotationByName("spine_01", 
		FRotator(45, 45, 45), EBoneSpaces::WorldSpace);	 

	 
	m_pSkeletalMesh = this->SkeletalMesh;
	if (m_pSkeletalMesh) {
		UE_LOG(LogSkeletalMesh, Warning, 
			TEXT("m_pSkeletalMesh set :D"));

		m_pSkeleton = m_pSkeletalMesh->Skeleton;
		if (m_pSkeleton) { 
			UE_LOG(LogSkeletalMesh, Warning, 
				TEXT("m_pSkeleton set :D"));
		} 
		else
		{
			UE_LOG(LogSkeletalMesh, Warning, 
				TEXT("m_pSkeleton NOT set ....."));
		}
	}
	else
	{
		UE_LOG(LogSkeletalMesh, Warning, 
			TEXT("m_pSkeletalMesh NOT set ....."));
	}


	UE_LOG(LogSkeletalMesh, Warning, 
		TEXT("END OF UMyPoseableMeshComponent CONSTRUCTOR!!!"));
} 

If there is any information missing or not fully described, I will try to provide or correct them. :slight_smile:

Ok I found out that reason for it being not set in the Constructor of the class MyPoseableMeshComponent:

The values set by the UE-Editor aren’t passed along inside the Constructor. I always thought something magically appeared beforehand, that already set the member m_pSkeletalMesh which is visible to the editor by the macro UPROPERTY(VisibleAnywhere, Category = ATEST). The member is set somewhere after in time.

  • Not sure when that happens though.
    Would be nice to know.

To improve my code so the member is updated and set on construction I added the code:

#if WITH_EDITOR
void UMyPoseableMeshComponent::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent)
{
	UE_LOG(LogSkeletalMesh, Warning, TEXT("UMyPoseableMeshComponent::PostEditChangeProperty(...)"));

	if (m_pAltMeshAsset) {
		UE_LOG(LogSkeletalMesh, Warning, TEXT("set SkeletalMesh to the one set in UE-Editor :D"));
		this->SetSkeletalMesh(m_pAltMeshAsset, true);
	}
	else {
		UE_LOG(LogSkeletalMesh, Warning, TEXT("The SkeletalMesh set in UE-Editor is NULL :("));

	}

	Super::PostEditChangeProperty(PropertyChangedEvent);	// triggers completly new construction of this!
}
#endif

which basically is called when a property on this object has been modified externally (e.g. by UE-Editor). And also called the constructor of UMyPoseableMeshComponent again.Not sure whether that’s how you would do it. If someone has a better solution to it, don’t hesitate to provide your solution.

Something else I found out. The UE-Editor assignments aren’t set after calling PostInitProperties and PostLoad

void UMyPoseableMeshComponent::PostInitProperties()
{
	UE_LOG(LogSkeletalMesh, Warning, TEXT("PostInitProperties start: UMyPoseableMeshComponent (called after constructor)"));
	Super::PostInitProperties();
	// no UE_editor properties being assigned to this component yet
}

void UMyPoseableMeshComponent::PostLoad()
{
	UE_LOG(LogSkeletalMesh, Warning, TEXT("UMyPoseableMeshComponent::PostLoad()"));
	Super::PostLoad();
	// no UE_editor properties being assigned to this component yet
}

similar questions: