Hi! I have a Little problem with my code,whe i execute the UE crash,any idea?Thanks
CameraMotion.h
#pragma once
#include "GameFramework/Actor.h"
#include "CameraMotion.generated.h"
UCLASS()
class IIWW_API ACameraMotion : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ACameraMotion();
UPROPERTY(EditAnywhere)
AActor* CameraOne;
UPROPERTY(EditAnywhere)
AActor* CameraTwo;
float TimeToNextCameraChange;
int cambio;
//Funtions
void cambioSuma() {
cambio += 1;
}
void cambioRestar() {
cambio -= 1;
}
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
};
CameraMotion.cpp
#include "IIWW.h"
#include "CameraMotion.h"
// Sets default values
ACameraMotion::ACameraMotion()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void ACameraMotion::BeginPlay()
{
Super::BeginPlay();
cambio = 0;
}
// Called every frame
void ACameraMotion::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
const float TimeBetweenCameraChanges = 2.0f;
const float SmoothBlendTime = 0.75f;
TimeToNextCameraChange -= DeltaTime;
if (TimeToNextCameraChange <= 0.0f) {
TimeToNextCameraChange += TimeBetweenCameraChanges;
APlayerController* OurPlayerController = UGameplayStatics::GetPlayerController(this, 0);
if (OurPlayerController) {
if ((OurPlayerController->GetViewTarget() != CameraOne) && (CameraOne != nullptr) && cambio==0) {
OurPlayerController->SetViewTargetWithBlend(CameraOne, SmoothBlendTime);
}
else if ((OurPlayerController->GetViewTarget() != CameraTwo) && (CameraTwo != nullptr) && cambio ==1) {
OurPlayerController->SetViewTargetWithBlend(CameraTwo, SmoothBlendTime);
}
}
}
InputComponent->BindAction("Right", IE_Pressed, this, &ACameraMotion::cambioSuma);
InputComponent->BindAction("Left", IE_Pressed, this, &ACameraMotion::cambioRestar);//This lines produce the crash
}