# Can't add element to TArray from Plugin

**URL:** <https://forums.unrealengine.com/t/cant-add-element-to-tarray-from-plugin/555086>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [May 12, 2022, 2:05am UTC](https://forums.unrealengine.com/t/cant-add-element-to-tarray-from-plugin/555086 "2022-05-12T02:05:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cheetor2502](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cheetor2502](https://forums.unrealengine.com/u/Cheetor2502)\
**Post date:** [May 12, 2022, 2:05am UTC](https://forums.unrealengine.com/t/cant-add-element-to-tarray-from-plugin/555086/1 "2022-05-12T02:05:55Z")

</div>

I’m getting this weird issue when trying to add an item to a TArray on my component.  
So I have a component that I’ve added to a character in in blueprint. This component comes from a plugin that I created. This component contains a list:  
UPROPERTY(Instanced, EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = “true”))  
TArray\<TObjectPtr\> LoadoutSlots;  
Now when trying to add an item the correct option shows up but when clicking it nothing happens and it doesn’t get added.  
I tried just adding that list directly on the player and not use the component from the plugin and that works, so it seems to be a plugin issue.  
The weird thing is I’ve been able to add the item properly in the past but this issue seems to happen randomly.

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [May 12, 2022, 2:21am UTC](https://forums.unrealengine.com/t/cant-add-element-to-tarray-from-plugin/555086/2 "2022-05-12T02:21:16Z")

</div>

Hi Cheetor2502,

Are you sure you’re wanting the pointer as a TObjectPtr? Here is the description in the source code:

- TObjectPtr is a type of pointer to a UObject that is meant to function as a drop-in replacement for raw pointer
- member properties. It is size equivalent to a 64-bit pointer and supports access tracking and optional lazy load
- behavior in editor builds. It stores either the address to the referenced object or (in editor builds) an index in
- the object handle table that describes a referenced object that hasn’t been loaded yet. It is serialized
- identically to a raw pointer to a UObject. When resolved, its participation in garbage collection is identical to a
- raw pointer to a UObject.
- 
- This is useful for automatic replacement of raw pointers to support advanced cook-time dependency tracking and
- editor-time lazy load use cases. See UnrealObjectPtrTool for tooling to automatically replace raw pointer members
- with FObjectPtr/TObjectPtr members instead.

Have you tried defining it as TArray\<TWeakObjectPtr\> to see if it is handled correctly like that?

---

<div class="post-metadata">

**Author:** ![Cheetor2502](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cheetor2502](https://forums.unrealengine.com/u/Cheetor2502)\
**Post date:** [May 12, 2022, 1:58pm UTC](https://forums.unrealengine.com/t/cant-add-element-to-tarray-from-plugin/555086/3 "2022-05-12T13:58:39Z")

</div>

Hello RecourseDesign,

In this case I don’t think I can use TWeakObjectPtr if the UPROPERTY is Instanced.

The part that confuses me about this issue is that if I move this code into the game directly and not through a plugin it works as expected.

---

<div class="post-metadata">

**Author:** ![DF\_JGregg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DF\_JGregg](https://forums.unrealengine.com/u/DF_JGregg)\
**Post date:** [May 17, 2022, 1:48am UTC](https://forums.unrealengine.com/t/cant-add-element-to-tarray-from-plugin/555086/4 "2022-05-17T01:48:39Z")

</div>

I encountered a similar issue. The object class that the array was made up of had a property with a nested category.

Example:  
UPROPERTY(BlueprintReadOnly, EditAnywhere, **Category = "Main|SubCategory**")  
bool m\_bSomeBool = true;

Removing the nested category fixed the issue.  
“Main|SubCategory” → “MainSubCategory”

---

<div class="post-metadata">

**Author:** ![Cheetor2502](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cheetor2502](https://forums.unrealengine.com/u/Cheetor2502)\
**Post date:** [May 24, 2022, 3:36pm UTC](https://forums.unrealengine.com/t/cant-add-element-to-tarray-from-plugin/555086/5 "2022-05-24T15:36:14Z")

</div>

Hello DF\_JGregg,

Unfortunately for me the object class doesn’t have a nested category.

---

<div class="post-metadata">

**Author:** ![Kory](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kory](https://forums.unrealengine.com/u/Kory)\
**Post date:** [August 23, 2023, 5:13pm UTC](https://forums.unrealengine.com/t/cant-add-element-to-tarray-from-plugin/555086/6 "2023-08-23T17:13:06Z")

</div>

> [@Cheetor2502](#):
>
> TArray LoadoutSlots;

What is the UObject class behind LoadoutSlots?

It should be something more like this:

```auto
TArray<TObjectPtr<ULyraSlot>> LoadoutSlots;

```
