Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

AnswerHub Maintenance

Background maintenance is scheduled to occur between 9 - 11am EDT on Tuesday, May 21. Site operation may be slower than normal during this time and a brief interruption in operation may be observed

Crash When Adding Static Mesh to Actor [C++]

UPDATE: For those who do a search and get this.

I've deduced the crash was actually from the // Code stuff about basic int32 math that hasn't yet crashed., as although I thought I had tested it in all cases, I hadn't, and I guess I changed something at the same time I added the static mesh stuff.

Adding static meshes to actors is as follows:


     UPROPERTY(BlueprintReadWrite, EditAnywhere)
     class UStaticMeshComponent* YourMesh;


     YourMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("YourMesh"));
     static ConstructorHelpers::FObjectFinder<UStaticMesh> YourMeshObject(TEXT("/Game/TheMeshYouWant")); // wherein /Game/ is the Content folder.

Howdy all.

I have a for loop wherein a "room" class is created a certain number of times. As of yet, this class has only contained some basic information, like what type of room it is, it's length and width, where it should be placed, etc. I'm trying to visualize this in the editor by adding a StaticMeshComponent to the actor. Doing so causes the editor to crash in a heaping pile of fire and quietly muttered expletives.

The For Loop:

 for (int i = 0; i < NumberFrameRects; ++i)
         ACRoom01* aNewRect = GetWorld()->SpawnActor<ACRoom01>();
         // Code stuff about basic int32 math that hasn't yet crashed.


 UPROPERTY(BlueprintReadWrite, EditAnywhere)
         class UStaticMeshComponent* Block;

Only when those two lines are added, when a StaticMeshComponent is added to this item, does the game crash.

Product Version: UE 4.8
more ▼

asked Aug 11 '15 at 02:00 PM in C++ Programming

avatar image

150 17 26 38

avatar image gamer08 Aug 11 '15 at 02:25 PM

Hello Kowbell, I've you tried to assign this staticMeshh in code (in the class constructor for example) to see if it's still crash?

At a first glance, it seems he tries to reference a "null" object and that why he crashes

Also if possible, can you post the error it throw you when it crashes?

avatar image Kowbell Aug 11 '15 at 02:44 PM

Gamer, Tried to give that a shot. Constructor is now as follows:

 // Sets default values
     PrimaryActorTick.bCanEverTick = true;
     static ConstructorHelpers::FObjectFinder<UStaticMesh> BlockDebugMesh(TEXT("Content'/Box_Brush_StaticMesh'"));

Unfortunately though, adding those two lines has created a new issue. Upon compiling, UE4 Editor crashed. The project will now no longer open. (Luckily I backed up last night :D)

What did I do wrong?

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Hey Kowbell-

To answer the second question first, declaring the static mesh component in your header and setting the static mesh in your constructor are two different things. To fix this you would want to take out the lines below "PrimaryActorTick" and replace them with Block = CreateDefaultSubobject(TEXT("Block")); With this, when you create a blueprint based on this class it will have a static mesh component attached to it. You can then set that static mesh through the editor or in code. To do so in code you would need to add a UStaticMesh pointer variable in your header (the same way you added the component) then use your ConstructorHelpers call and assign it to the static mesh rather than the static mesh component.

As for the crashes, the second crash is from trying to assign a static mesh to a static mesh property incorrectly. Without the log files (inside the project's Saved/Logs folder) it would be difficult to say what the cause of the first crash is.


Doug Wilson

more ▼

answered Aug 11 '15 at 03:25 PM

avatar image Kowbell Aug 11 '15 at 03:52 PM

Thanks Doug!

I'm trying to go the code route for that, but I can't seem to find what you mean with ConstructorHelpers.

Googling the problem, it seems like the code should look somewhat like this:

     Block = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Block"));
     BlockMesh = ConstructorHelpers::FObjectFinder(TEXT("Content/1x1x3Base.uasset"));

However, compiling yields this error: error C2955: 'ConstructorHelpers::FObjectFinder' : use of class template requires template argument list

I also tried

 static ConstructorHelpers::FObjectFinder<UStaticMesh> BlockStaticMesh(TEXT("/Content/1x1x3Base.uasset"));

but I can't seem to get that to work with Block->SetStaticMesh(BlockStaticMesh); given that the FObjectFinder doesn't appreciate the use of pointers.

avatar image Doug E ♦♦ STAFF Aug 11 '15 at 04:17 PM

You would use the ConstructorHelper as you did in your second post: static ConstructorHelpers::FObjectFinder BlockDebugMesh(TEXT("Content'/Box_Brush_StaticMesh'"));

After this you would set your BlockMesh to the mesh stored in BlockDebugMesh with BlockMesh = BlockDebugMesh.Object

avatar image Kowbell Aug 11 '15 at 04:42 PM

Still getting a 'use of class template requires template argument list' when using that. Is there an #include I'm forgetting, or should my constructor be more than ACBankRoom01::ACBankRoom01()?

avatar image Doug E ♦♦ STAFF Aug 11 '15 at 05:21 PM

Looking at the documentation for FObjectFinder (https://docs.unrealengine.com/latest/INT/API/Runtime/CoreUObject/UObject/ConstructorHelpers/FObjectFinder/index.html) it looks like the necessary include would be "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h" Let me know if adding the include helps or gives you the same/different message

avatar image Kowbell Aug 11 '15 at 05:29 PM

Same message when adding #include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h"

avatar image Doug E ♦♦ STAFF Aug 11 '15 at 05:35 PM

I'm a little confused on where this error is coming from. Is it pointing to the line of code with the ConstrutorHelper? If possible could you post the code for your class as well as the exact error message?

avatar image Kowbell Aug 11 '15 at 05:48 PM

It's that line, yup.


 error C2955: 'ConstructorHelpers::FObjectFinder' : use of class template requires template argument list
 'ConstructorHelpers::FObjectFinder' : class has no constructors

Files too big for comment, so here is the header, and here is the .cpp.

avatar image Doug E ♦♦ STAFF Aug 11 '15 at 06:00 PM

Looking at the source file it looks like you're missing the after FObjectFinder. This lets the compiler know what kind of object it's supposed to be finding.

avatar image Kowbell Aug 11 '15 at 06:06 PM

There's a space after FObjectFinder, if that's what you mean.

avatar image Doug E ♦♦ STAFF Aug 11 '15 at 06:52 PM

It seems AnswerHub doesn't like angle brackets. after FObjectFinder you also need to add

avatar image Kowbell Aug 11 '15 at 08:12 PM

Huzzah! That solved that problem. Thanks!

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question