TArray SetNum on Constructor Crashes the Editor

Calling SetNum on my class constructor crashes the editor on startup (crashed from hot reloading when compiled, and then on every start).

No stack is created.

Editor Version is 4.6.1, downloaded from the standalone.

On Header:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory") TArray<FInventoryItemStruct> Items;

On Constructor:

Items.SetNum(11);

Edit:

To better clarify, my class is a component derived from UActorComponent and is used in a player character (I inserted it there before it crashed).

Edit2: Corrected TArray class.

Hi Mielke,

Sorry for taking so long to get back to you on this issue. I tried to reproduce the results that you described, but was unable to do so. Would you be able to provide a little more information?

  • Your original post may have cut the type of variable in your TArray. Is this UObject?
  • How are you adding this to your character Blueprint?
  • What additional code are you adding before performing a Hot Reload?

Hi!

Now it is working the way I posted (I tried to replicate the issue now and it worked, for reasons).

For completion:

  1. I corrected the array type. It is a custom Struct defined in the C++ as follows:
USTRUCT() struct FInventoryItemStruct { GENERATED_USTRUCT_BODY()
UPROPERTY()
int32 Quantity;

UPROPERTY()
class APickup* Item;

FInventoryItemStruct()
{
	Quantity = 0;
	Item = NULL;
}

};

  1. I am just adding it as a component inside the blueprint (not the c++ code)

  2. When I used hot reload I believe it was only that (I compile a lot). But it crashed after when I just tried to open the editor.

If you want I can try and get the earlier version that was not working with this code.

Hi Mielke,

Sorry, I’ve been swamped the past few weeks. I tried again with the additional information that you provided (thank you for that), but I believe everything is still working correctly for me. Can you confirm that it is now working as you expect?

Hi Mielke,

We have not heard back from you for a while. Do you still need help with this issue? I will be marking this issue as resolved for tracking purposes, but if you still need any help please feel free to re-open this post.