# TArray::Num() and other methods crash the engine

**URL:** <https://forums.unrealengine.com/t/tarray-num-and-other-methods-crash-the-engine/422531>\
**Category:** C++\
**Tags:** tarray, add, unreal-engine, crash, CPP, question\
**Created:** [April 13, 2018, 2:00pm UTC](https://forums.unrealengine.com/t/tarray-num-and-other-methods-crash-the-engine/422531 "2018-04-13T14:00:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arty-McLabin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arty-mclabin/32/1012076_2.png) [@Arty-McLabin](https://forums.unrealengine.com/u/Arty-McLabin)\
**Post date:** [April 13, 2018, 2:00pm UTC](https://forums.unrealengine.com/t/tarray-num-and-other-methods-crash-the-engine/422531/1 "2018-04-13T14:00:33Z")

</div>

I don’t have a clue why, but in one of my classes, calling TArray methods crash the engine. like it were a nullptr to TArray, rather than a regular member value. why does it even happen? i use TArrays for so long so far and didn’t encounter such a behaviour.

```
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class DEGRADATION_ERA_API UInventory : public UActorComponent
{
	GENERATED_BODY()

public:	
	...
	TArray<int> array_temp; // <int> just for the sake of test simplicity. fails for other types too.
        ...
        void foo(){array_temp.Add(5);} // No matter if i try to Add(), Num() or whatever other method of TArray, it just crashes the engine upon running.
};
```

---

<div class="post-metadata">

**Author:** ![Arty-McLabin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arty-mclabin/32/1012076_2.png) [@Arty-McLabin](https://forums.unrealengine.com/u/Arty-McLabin)\
**Post date:** [April 13, 2018, 3:17pm UTC](https://forums.unrealengine.com/t/tarray-num-and-other-methods-crash-the-engine/422531/2 "2018-04-13T15:17:27Z")

</div>

Okay i am an idiot.

This is a UActorComponent child class and i have forgot to init the component in his parent actor:

```
inventory = CreateDefaultSubobject<UInventory>(TEXT("inventory")); //in Actor constructor

```

FIN
