Weird Behavior When Add Something To TArray in Blueprint

Hello everyone,

I have an actor which has an inherited TArray variable from C++. I added some components to the actor and I want to store those components in the TArray variable. When I add those components in the Blueprint, the array acts weird. I just add 1 component but it shows me that the array has 7 elements or something like that. (That number is always random when I close and open the editor.) When I try to access a variable of the array, it gives me an error. Even the 0th (first) element gives me an error.

I tried to add those component by using both BeginPlay and Construction functions, but it didn’t work.

NOTE: When I came across this issue before, I had to open a new project, copy all the C++ classes to the new project and create all the Blueprints again. Now, the project is big; so that I cannot create a new project to solve this issue.

I am not sure why this happens, but I have also another code which is similar in the same project, and it doesn’t give me any error and it works perfectly (even in the packaged project).

The problem is not about the size of the array. It is okay if the array has 7 or 11 or more elements. I check if the element is null or not. The interesting part is: even though I check null pointers, the code says the element is not null. I do something in the code by using the element and it gives me an error as if the element is null.

Hey,

Remove that from the construction script and keep it in the begin play
You may need to clear you array in the bp once to be sure

I’ve had problems with arrays holding some previous content, and got around it by just clearing them at the start.

I think it only happens with array which have a default number of slots.

I just wanted to show that I tried both BeginPlay and Construction. I am not using the both functions at the same time.

Clearing function at the beginning works, but I use same logic in a different actor and it works.

Yup, had that too. But like I say, only when the array has some default cells.