FindComponentByClass() in class Constructor make runtime error

UActorAnimationController::UActorAnimationController() // Constructor
{
	USkeletalMeshComponent* const skeletalMeshComponent = GetOwner()->FindComponentByClass<USkeletalMeshComponent>();
    ~~
    ~~
}

.

return (T*)FindComponentByClass(T::StaticClass());

This code makes runtime error.

I think this is because Unreal engine don’t make reflection data yet.
I think I should move this FindComponentByClass to other callback function.

This code is relevant with CDO object.
I should do setting value of CDO.

Where should i move this code to?

You could use:

virtual void InitializeComponent() 

https://docs.unrealengine.com/4.26/en-US/API/Runtime/Engine/Components/UActorComponent/InitializeComponent/

I think the error is because GetOwner() is probably NULL when the CDO is called. I’d check for NULL.
I do searches for other actors/components in other functions, outside the constructor.

If that doesn’t fix, could you post the error?

very likely GetOwner() is null, constructor is a c++ constructor, so it’d be called before anything else is done on the object. Also, does this class ever even have an Owner?

When posting an error, describe the error, not just “makes an error” :slight_smile:

Here’s a thread with a ton of possibilities for where you could handle runtime initialization logic for UObjects