x

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"

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.

Product Version: UE 4.10
Tags:
more ▼

asked Jun 01 '16 at 08:48 PM in C++ Programming

avatar image

Nepho
8 3 3 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Jun 02 '16 at 12:46 PM

avatar image

Nepho
8 3 3 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Jun 01 '16 at 09:54 PM

avatar image

Nachtmahr
7k 143 28 172

avatar image Nepho Jun 01 '16 at 10:09 PM

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.

avatar image Nepho Jun 01 '16 at 10:17 PM

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.

avatar image Nachtmahr Jun 01 '16 at 10:48 PM

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.

avatar image Nepho Jun 02 '16 at 07:45 AM

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?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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