0

I'm currently creating a little video sequence for a game in Unreal and have written a CameraDirector-class for this purpose. At the name says, it controls the players view around different camera objects played in the world.

Now I want to make my program more flexible, so I decided to put all the Camera's into an std::vector-container and use a for file to iterate through it. Now here is the problem:

#include <vector>
using namespace std;

When I put this in the header to import the std::vector, a LOT of the standard stuff created automatically by Unreal-Engine was underlined red and was no longer recognized by VS. I didn't touch a lot of this stuff, but nevertheless it wont compile anymore.

When I remove these two lines everything is fine again but I can't use std::vector.

Why does my import interferes with the program so much?

I'm using VS-2015 and Unreal Engine 4.17.1

Edit:

Due to being marked as a duplicate, it also breaks as well when I ONLY write #include <vector>. I don't see the connection to the linked question

Code in the header:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "CameraDirector.generated.h"

#include <vector>


UCLASS()
class HOWTO_AUTOCAMERA_API ACameraDirector : public AActor
{
    GENERATED_BODY()
    
public: 
    // Sets default values for this actor's properties
    ACameraDirector();

    APlayerController* OurPlayerController = UGameplayStatics::GetPlayerController(this, 0);

    const float TimeBetweenCameraChanges = 4.0f;
    const float SmoothBlendTime = 0.75f;
    const float SlowBlendTime = 1.5f;

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

public: 
    // Called every frame
    virtual void Tick(float DeltaTime) override;

    bool isAllCamerasSelected();

    void createNewCameraMove(AActor* Camera, float movingTime);
    
    UPROPERTY(EditAnywhere)
        AActor* CameraOne;

    UPROPERTY(EditAnywhere)
        AActor* CameraTwo;

    UPROPERTY(EditAnywhere)
        AActor* CameraThree;

    float TimeToNextCameraChange;
};

.cpp :

// Fill out your copyright notice in the Description page of Project Settings.

#include "CameraDirector.h"
#include "Kismet/GameplayStatics.h"




// Sets default values
ACameraDirector::ACameraDirector()
{
    // 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 ACameraDirector::BeginPlay()
{
    Super::BeginPlay();
    
}

// Called every frame
void ACameraDirector::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    TimeToNextCameraChange -= DeltaTime;


    if (TimeToNextCameraChange <= 0.0f)
    {
        TimeToNextCameraChange += TimeBetweenCameraChanges;
        
        if (OurPlayerController && isAllCamerasSelected())
        {
            if ((OurPlayerController->GetViewTarget() != CameraTwo) && (OurPlayerController->GetViewTarget() != CameraThree))
            {
                // Blend smoothly to camera two.
                OurPlayerController->SetViewTargetWithBlend(CameraTwo, SmoothBlendTime);
            }
            else if ((OurPlayerController->GetViewTarget() != CameraOne) && (OurPlayerController->GetViewTarget() != CameraThree))
            {
                // Blend slowly to camera three.
                OurPlayerController->SetViewTargetWithBlend(CameraThree, SlowBlendTime);
            }
            else if ((OurPlayerController->GetViewTarget() != CameraTwo) && (OurPlayerController->GetViewTarget() != CameraOne))
            {
                // Cut instantly to camera one.
                OurPlayerController->SetViewTarget(CameraOne);
            }
        }
    }
}

bool ACameraDirector::isAllCamerasSelected()
{
    return ((CameraOne != nullptr) && (CameraTwo != nullptr) && (CameraThree != nullptr));
}

void ACameraDirector::createNewCameraMove(AActor * Camera, float movingTime)
{
    OurPlayerController->SetViewTargetWithBlend(Camera, movingTime);
}

Severity Code Description Project File Line Error (active) name followed by '::' must be a class or namespace name HowTo_AutoCamera d:\Leon\Unreal\HowTo_AutoCamera\Source\HowTo_AutoCamera\CameraDirector.cpp 10

Community
  • 1
  • 1
h_e_u_r_e_k_a
  • 115
  • 2
  • 2
  • 21
  • Why is this a duplicate? – h_e_u_r_e_k_a Sep 17 '17 at 18:11
  • What if there's a symbol `vector` in the Unreal Engine code you include? Considering that "vectors" (in the mathematical sense) are very common in 3d-math and -programming it seems likely. Without more context and information it's impossible to say anything else. Please [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask) and learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve) (if you haven't already, if you have then please do it again) and edit your question to show at least some of the errors. – Some programmer dude Sep 17 '17 at 18:15
  • Okay, the problem doesn't seem to be the `using` statement. However, the error you show is about line 10 in the *source* file `CameraDirector.cpp`, which you don't show us. – Some programmer dude Sep 17 '17 at 18:31
  • Whoops! Provided this code as well ! ^^ – h_e_u_r_e_k_a Sep 17 '17 at 18:41
  • Unrelated to the problem: Unreal Engine (and most game engines in general) come with their own container implementations (in this case [`TArray`](https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/TArrays/)) which should be used instead of the ones from the C++ standard library – UnholySheep Sep 17 '17 at 20:46

0 Answers0