Download

Why is my UE acting weird?

Here is my code in my header file of an object that I placed in world:



UPROPERTY()
TArray<ASplineConnectionPoint*> SplineConnectionPoints = {};


I tried to find why my game was crashing at the beginning. Then I found out, for some reason, This TArray contains 28 elements at the beginning of the game when it should only have 1 (I only register 1 element to it). I deleted intermediate-saved-binaries folders, rebuilt my game, closed-reopened UE4 but nothing worked. Then I decided to add SplineConnectionPoints.Empty() in BeginPlay and now it finally works as intended. Where did that 28 elements come from? Why are my variables not reset even tho i tried everything?

This wasn’t happening for weeks, and this class decided to act funny for some reason unknown to me. I checked all references and I never add anything to this array except for 1 element. Now after .Empty line only 1 element is in this array and my game works as intended.

Ok I found it…

I was getting my actors with TObjectIterators. Somehow, this garbage return empty/wrong actors even though I only have one actor spawned in the world.