Why does using a ConstructorHelper function cause a crash?

Running a constructor helper function during run time crashes my game.

static ConstructorHelpers::FObjectFinder xyz(TEXT("SkeletalMesh'/Game/Dir/abc.abc'"));

Hi . Could you please provide some more information about what is happening? Please check this post to get an idea of what information is helpful for us to be able to investigate what is happening.

Make sure:

static ConstructorHelpers::FObjectFinder xyz(TEXT("SkeletalMesh'/Game/Dir/abc.abc'"));

is in the constructor, which will resemble something like:

AObjectFinder::AObjectFinder(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)

and be at the top of your cpp (usually)

Hi ,

We have not heard back from you for a while, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with any additional information you may have and we will offer further assistance.

Thank you.

I’m not sure if I can just message you via AnswerHub instead of replying to your comment (so feel free to delete this reply after reading it) but I wanted to ask - why are questions marked as resolved when the person has not responded to the answer(s)?

I have found a couple of times questions have been marked as resolved by staff, thinking I am likely going to come across a fix for a problem I have, only to find any answers given do not help resolve the issue. It also means it is less likely for people to look over them and provide the correct answer or other solutions.

I stumbled on him asking this in another question and he was asked to make a new question; since I have one solution, I figured I’d look at his questions but noticed this was marked as resolved so almost didn’t bother. Although the answer given was likely the solution to his problem, I have found questions in the past marked as resolved when there is no helpful answer.

In case anyone has this problem and they are already using it in the constructor - if you are working with a Blueprint and don’t add _C to the end of the path, you will get “Error: CDO Constructor: Failed to find…”. A Blueprint path like “Class’Game/Blueprints/MyGameItem.MyGameItem’” would be constructed like the following:

static ConstructorHelpers::FObjectFinder<UClass> playerBlueprintClass(TEXT("Class'Game/Blueprints/MyGameItem.MyGameItem_C'"));

You need to make sure it is before the apostrophe and quotations at the end.

This is not the case with something like a skeletal mesh though and is for reference for anyone having trouble with Blueprints.

As Dune states in his answer, the constructor helper functions have to be called within a constructor, as do PCIP functions (like CreateDefaultSubobject). To dynamically change things like skeletal meshes at run-time, you will want to get them during construction and store a reference to the object, like so:

static ConstructorHelpers::FObjectFinder<USkeletalMesh> xyz(TEXT("SkeletalMesh'/Game/Dir/abc.abc'"));
MyClassSkeletalMeshReference = xyz.Object;

If, for some reason, you want to load up something like a skeletal mesh outside of the constructor, instead of doing the above, you can do the following instead:

USkeletalMesh* skeletalMesh = Cast<USkeletalMesh>(StaticLoadObject(USkeletalMesh::StaticClass(), NULL, TEXT("SkeletalMesh'/Game/Dir/abc.abc'")));

Hi @Furinyx,

Thanks for the question. Any AnswerHub post that a staff member comments on or answers is tracked internally. If there has been no response for a while from the user who posted the question, either to provide more information or to select an answer that resolved the issue, we will post a message similar to the one I posted and mark the issue as resolved. For our tracking purposes, this indicates that we do not intend to take any further action on that post unless it is re-opened. Any new comment or answer that is posted to a Resolved question will re-open it, and place it back into our tracking system.

Unfortunately this means that some AnswerHub posts do get marked as “Resolved” even though they really haven’t been (or the user solved the issue themselves and never came back to update the post). You are more than welcome to post on Resolved posts if you have more information that would be helpful for resolving, or preventing, the issue in that post. In fact, we would like for you to do that, since having more information available to the other users on the AnswerHub is definitely a good thing.

Another thing that is slightly related to this is that the AnswerHub will automatically select any answer posted by a staff member as the correct answer, and will do the same if a staff member posts a comment on an answer made by a staff member. In this instance, we have to manually deselect the answer after posting it, but we don’t always remember to do that.

I hope that answered your question. Have a great day!

PS. If you ever need to get in touch with me directly, you can send me a PM on our forums. My username there is the same as it is here.

How do you do this for USkeletalMeshComponents?

Hi Dark583,

Sorry for the delayed response to your question. Could you clarify what you are looking for? Are you trying to set a Skeletal Mesh in a Skeletal Mesh Component, or are you trying to create a Skeletal Mesh Component?

Want to highlight “the constructor helper functions have to be called within a constructor”. Helped in my case.