Constructor call crashing the editor (UObject() constructor called but...)

Hello community,

I’ve been working on a small project for some time.
Now what I’m trying to do is rather simple : attach an AActor object to a skeletal mesh socket. I created a generic class for my pieces of gear (helmet, sword…), so my helmet class inherits from the gear class. I put some code in it, but it crashes the UE4 editor! The log didn’t allow me to understand why this was happening. Here it is.

And here are my cpp file and my header.

Does anyone know what’s wrong? I tried initializing the model parameter outside of the initialization list in Gear’s constructor, but it doesn’t change anything.

Thanks in advance and sorry if my explanation is lacking pieces.

Edit: Adding the class where I (try to) instantiate my helmet : header and cpp file. I commented the bit where I tried using the NewObject() method (having this time a pointer to my ATTTHelmet in the parameters, commented out too). NewObject() also causes a crash.

Here are the header and cpp file of my Helmet class, though I don’t think this is where the problem is.

You have to show me a bit more. How are you Creating Your Helmet and where? can you show the line. I hope you did not use “new ATTTHelmet()” to Construct the Helmet? The error msg you Posted is missing a Piece but if I look at line 2071 (in 4.10) it says you did not use NewObject to construct your Helmet.

Okay, so I tried using NewObject() without success. The editor is still crashing. I’m updated my original post right now to include the part where I create my helmet.

Hello, and thanks for the answer. I can’t check right now but I’m fairly certain that I initialize its value in my character’s constructor’s initialization list, by calling the helmet’s constructor. In 5 minutes I can update the code to include this.

Edit: oh. I realized that doing this might implicitly use the new keyword… I’ll try with NewObject.

ok in your Character

ATTTScrollCharacter::ATTTScrollCharacter()
    : Super()
    , helmet()

remove the , helmet() and uncomment the line where you use NewObject

headSocket = charSkeletal.Object->FindSocket("HeadSocket");

if you get the Socket from something you dont need to create a Socket in the Constructor you can remove the line there in the Constructor.

in the .h of your character make the helmet a pointer*

In your gear .cpp same remove the model and use the CreateDefaultSubObject line.

Thats it if I did not overlook something. You should use int32 instead of int. At least if you want to use them as UPropertys later UE4 will complain about them.

Let me know if that fixed it for you if not give me a Update on the Errors it spits out.

Edit: You also never set a root or attached Components to each other you maybe want to fix that up too.

Hey, thanks for giving it a look! So I replaced the code like you said, and removed the CreateDefaultSubobject for the socket because it didn’t make much sense indeed. But now the engine is crashing because of the « helmet = NewObject(this); » line. Here is the log… Any idea what’s going on?

Okay, so I found out what was wrong.

I was trying to create an AActor object either by using its constructor, or by using NewObject(). These two methods are not how you deal with AActor. You actually have to spawn it at runtime (usually BeginPlay()) by using GetWorld()->SpawnActor().

Hope it helps someone in the future.