I’m confused how to use TArray.
It’s three times encounter TArray error.
The first. I use TArray store some template data point to sort. I push data in BeginPlay() function. But after when i used. All point in this container has turn invalid, not nullptr, just some error data or fdfdfd etc. I checked if the template data has been destruct. But all data is fine. I don’t know what happen and no time to spent on it. So i change my way to use the template data’s array index to solve this.
The second. I make a TArray to store some int variable. The requirement is every time when new data list come in, clear old and push all new data into array. Then update by index when used. So i write a function, and put .Empty() function at first. The first set data come from local file. So, i call this function in constructor to load default data. And crash. Like the first one, i can only change way to use std container.
And now. I write a component. I want two element in TArray container when the component add to actor. So, i make this in constructor. and crash again. Them i change is to PostInitProperties function and crash again and again. Just different position in stack.
Some one can tell me how to use TArray in constructor?
the data:
USTRUCT(BlueprintType)
struct FRopeAttachInfo
{
GENERATED_USTRUCT_BODY()
/* The rope's particle point index */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Component)
int32 m_Index;
/* The socket name on the attach object */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Component)
FName m_SocketName;
/* The attach object data */
UPROPERTY(EditAnywhere, Category = Component)
FComponentReference m_AttachObject;
/* The offset from attach position */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Component, meta = (MakeEditWidget = true))
FVector m_OffSet;
};
the container:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Rope")
TArray<FRopeAttachInfo> m_AttachData;
and the constructor
URopeComponent::URopeComponent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
PrimaryComponentTick.bCanEverTick = true;
bTickInEditor = true;
bAutoActivate = true;
bAttachStart = true;
bAttachEnd = true;
RopeWidth = 10.f;
m_AttachPointIndex = NumSegments = 10;
NumSides = 4;
EndLocation = FVector(100.f, 0, 0);
RopeLength = 100.f;
SubstepTime = 0.02f;
SolverIterations = 1;
TileMaterial = 1.f;
CollisionFriction = 0.2f;
RopeGravityScale = 1.f;
FRopeAttachInfo tHead;
tHead.m_Index = 0;
m_AttachData.Add(tHead);
FRopeAttachInfo tEnd;
tEnd.m_Index = NumSegments - 1;
tEnd.m_OffSet = FVector(100.0f, 0.0f, 0.0f);
m_AttachData.Add(tEnd);
SetCollisionProfileName(UCollisionProfile::PhysicsActor_ProfileName);
}
stack:
> UE4Editor-CoreUObject.dll!TFastReferenceCollector<1,FGCReferenceProcessor<1>,FGCCollector<1>,FGCArrayPool,0>::ProcessObjectArray(FGCArrayStruct & InObjectsToSerializeStruct, const TRefCountPtr<FGraphEvent> & MyCompletionGraphEvent) 行 696 C++
UE4Editor-CoreUObject.dll!TFastReferenceCollector<1,FGCReferenceProcessor<1>,FGCCollector<1>,FGCArrayPool,0>::FCollectorTaskQueue::DoTask() 行 381 C++
UE4Editor-CoreUObject.dll!TGraphTask<TFastReferenceCollector<1,FGCReferenceProcessor<1>,FGCCollector<1>,FGCArrayPool,0>::FCollectorTaskProcessorTask>::ExecuteTask(TArray<FBaseGraphTask *,FDefaultAllocator> & NewTasks, ENamedThreads::Type CurrentThread) 行 829 C++
UE4Editor-Core.dll!FTaskThreadAnyThread::ProcessTasks() 行 934 C++
UE4Editor-Core.dll!FTaskThreadAnyThread::ProcessTasksUntilQuit(int QueueIndex) 行 800 C++
UE4Editor-Core.dll!FTaskThreadBase::Run() 行 516 C++
UE4Editor-Core.dll!FRunnableThreadWin::Run() 行 76 C++
UE4Editor-Core.dll!FRunnableThreadWin::GuardedRun() 行 25 C++
Code
link text