Editor crashes when adding a new instance of custom class in c++
I want to implement an inventory system in my project. To do so, I created a c++ class which derives from AActor and its only purpose is to control an array. Then I want to create an instance of that class inside my character's class. First I declare the new variable in the .h file of my character class using:
Then I declare the new instance in the .cpp file of my character class:
When I do this, the editor crashes when reaching about 92% loading with no crash report. I've tested this using UE 4.8 and it happens again. I know crashes occur when I add the declaration of the new instance since everything goes back to normal when I comment that line. What am I doing wrong? Is there another way to do this?
Thanks in advance!
asked Jun 24 '15 at 05:33 PM in C++ Programming
If you want to create an inventory that is editable via edior, you should derive it from USceneComponent instead of AActor. Thus you be able to attach one to your actor:
Besides the better code handling and using of flexible component system, this solution possibly should eleminate your crash problem because it is more transparent way than a creating AActor-deriving subclass with attaching to another actor (IMO).
From a trouble shooting standpoint I would suggest first checking to ensure your crash is occurring at the line you set the inventory to "NewNamedObject". If you comment out that line and the editor opens up without a problem then you know that is your problem area. My hunch is that that is a part of your problem.
If that is indeed the issue Change your Player Character to use the ObjectInitializer
not entirely sure why but I recall having trouble using the standard ConstructObject functions in Constructors.
answered Jun 24 '15 at 05:45 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here