TArray(AActor*,FDefaultAllocator) <-> AActor* cant transform

TArray<AActor*>* m_pArray

void Function(AActor* _obj)
{
if(m_pArray == NULL)
  m_pArray = new TArray<AActor*>();

m_pArray->Add(_obj);

AActor* temp = m_pArray[0]; //imposiible!!

}

there is no apposite transform function TArray(AActor*,FDefaultAllocator) <-> AActor*

??? … why?

Man… Read something about basics in c++, please =)

Your m_pArray is pointer to TArray, not TArray itself, so if you wanna access it, you must call (*m_pArray)[0].

And I don’t see where you delete your TArray, so I would recommend you read this article

God… sorry it’s my mistake;

i understand that if i add UPROPERTY() upper value like this

UPROPERTY()

TArray* m_pArray

then thatvalue’s GarbageCollector is valid, auto delete value.

but in my Question of code’s value doesn’t have UPROPERTY()

so… I have to passively Delete this value.

right?

Yup, but best practice is to mark it as UPROPERTY. And here I don’t see big deal to make pointer TArray as it holds pointers and don’t consume much memory.

I add UPROPERTY(), thank you for your answer :slight_smile:

Never use “new” or “delete” in UE4 or else you really need to (like instatiate non-UObject classes, which some editor apis require), let UE4 deal with,

TArray don’t need to be pointer because all it does is manage native array pointer so it’s kind of like making pointer of pointer and as Josh said reflection system does not support this kind of setup.

Also converted alkohol comment to anwser since… it’s answer and he is right :stuck_out_tongue: Don’t be shy to post anwser even if you not sure,

UPROPERTY on a TArray<> * is not supported.

You don’t need to allocate your heap memory for a TArray, just make it a member of your class. The garbage collector won’t be able to traverse that data structure and your AActors are going to get removed without your knowledge. Then crash :frowning: