Hello, I have a problem with changing background sprite position. I change it’s location like this
auto ex = Backgrounds[0]; ex->SetActorLocation(FVector(0.0f, -100.0f, positionZ)); positionZ++;
But when I tried to run this code, I UE crash with this error:
I think I should add my .h and .cpp files for more details
My header file:
UCLASS(minimalapi)
class APaperexamapleGameMode : public AGameMode
{
GENERATED_BODY()
public:
APaperexamapleGameMode();
void BeginPlay() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Background sprties")
TArray<ABackgroundSprite*> Backgrounds;
void Tick(float deltaSeconds) override;
float positionZ;
};
And my cpp file
void APaperexamapleGameMode::BeginPlay()
{
positionZ = 0.0f;
UWorld* const World = ();
if(World)
{
for (size_t i = 0; i < 6; i++)
{
//()->SpawnActor(ABackgroundSprite::StaticClass);
Backgrounds.Add((ABackgroundSprite*) World->SpawnActor<ABackgroundSprite>(ABackgroundSprite::StaticClass())->SetActorLocation(FVector(2048.0*i, -100.0f, 0.0f)));
}
}
}
void APaperexamapleGameMode::Tick(float deltaSeconds)
{
Super::Tick(deltaSeconds);
auto ex = Backgrounds[0];
ex->SetActorLocation(FVector(0.0f, -100.0f, positionZ));
positionZ++;
}