public:
// Sets default values for this actor’s properties
//ACubeActor();
//ACubeActor(FObjectInitializer& PCIP);
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
};
// Called when QtPushButton Cube is triggered in Qt
void UQtActorComponent::TestCallBack() {
FVector Position = FVector(FMath::RandRange(-1000,1000), FMath::RandRange(0, 1000), FMath::RandRange(1000, 10000));
FRotator Rotation = FRotator(0.0f);
//ArrayCubeActor.Push( GetWorld()->SpawnActor<ACubeActor>( Position, Rotation ));
//ArrayCubeActor.Push( GetWorld()->SpawnActor<ACubeActor>( ACubeActor::StaticClass() ));
//ArrayCubeActor.Push( (ACubeActor*)GetWorld()->SpawnActor( ACubeActor, &Position));
//ArrayCubeActor.Push( (ACubeActor*)GetWorld()->SpawnActor<ACubeActor>( Position, Rotation ));
//ArrayCubeActor.Push( SpawnActor<ACubeActor>( this ));
}
Is anyone maybe got a tutorial in UE 4.10, C++ helping me. Or a solution ?
Hi!
I receive recently the same error, and it happens becouse i try Spawn an Actor in a different thread. This usually happen when we try execute Async Tasks in different threads or are calling the spawn in functions being executed outside the Gamethread.
To guarantee it be called inside of the Gamethread i fireup a AsyncTask specifying the thread i want this be executed like this:
AsyncTask(ENamedThreads::GameThread, [this]()
{
SpawnRailCamera();
// Time when the press play...
StartTime = GetWorld()->GetTimeSeconds();
CurrentSplineTime = 0.0f;
SplineLength = GetRailSplineComponent()->GetSplineLength();
bLockOrientationToRail = IVR_FollowRail;
RailCam->IVR_StartRecord();
MoveCamera = true;
FinishRecording = false;
});
Everything inside of the AsyncTask {} , will be executed inside of the Gamethread. In this way, for example , code not related with the game itself can be executed outside of the main Game Thread without stuck the game, like database updates etc…
I see in your example some Qt comunication between you UE aplication and Qt , be carefull with this becouse all QObjects are managed by the QAplication Thread, so i strongly suggest you create functions that create new Qt Objects inside of the QtApp and return the pointers to the UE aplication. In this way you avoid Crashes and Memory Leaks in your project.
This is an example of how create new Objects in Qt to move them in the correct Qt Thread: