JustaCookie
JustaCookie

Reputation: 181

Unreal Engine 4.19 C++ Undeclared Identifier error, but it code IS declared

This was also posted to Unreal's AnswerHub, but they are pretty slow at responding and I was wondering if this is an Unreal Engine error or a Visual Studio 2013/C++ general error. I figure if it is a general error then StackOverflow would point it out.

Basically for no reason Visual Studio started having problems detecting code properly, saying there are unknown symbols inside of empty functions, then it started saying already working code had undeclared identifiers in it or that "->" wasn't known, etc. A different file gives me these errors https://i.sstatic.net/fOLRj.png below is the code that I am using to show my problem. When I tried it again it said it could not open ToggleForBP.generated.h

Is this an error with Visual Studio 2013 or with Unreal Engine?

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

#pragma once

#include "GameFramework/Actor.h"
#include "ToggleForBP.generated.h"

UCLASS()
class PLAYGROUND_API AToggleForBP : public AActor
{
    GENERATED_BODY()

public: 
    // Sets default values for this actor's properties
    AToggleForBP();

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

    // Called every frame
    virtual void Tick(float DeltaSeconds) override;


    //Toggles between on and off
    void SwitchOnOff();

    bool UniqueValueBlah;


};

My .cpp

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

#include "Playground.h"
#include "ToggleForBP.h"


// Sets default values
AToggleForBP::AToggleForBP()
{
    // 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;

}

void SwitchOnOff()
{

    UniqueValueBlah = true;
}

// Called when the game starts or when spawned
void AToggleForBP::BeginPlay()
{
    Super::BeginPlay();

}

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

}

The errors I get from the above code:

Error   2   error : Failed to produce item: D:\Unreal Projects\Playground\Binaries\Win64\UE4Editor-Playground-3827.dll  D:\Unreal Projects\Playground\Intermediate\ProjectFiles\ERROR   Playground
Error   1   error C2065: 'UniqueValueBlah' : undeclared identifier  D:\Unreal Projects\Playground\Source\Playground\ToggleForBP.cpp 18  1   Playground
Error   3   error MSB3073: The command ""D:\Programs\Epic Games\Epic Games\4.9\Engine\Build\BatchFiles\Build.bat" PlaygroundEditor Win64 Development "D:\Unreal Projects\Playground\Playground.uproject" -rocket -waitmutex" exited with code -1.   C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets   38  5   Playground
    4   IntelliSense: identifier "UniqueValueBlah" is undefined d:\Unreal Projects\Playground\Source\Playground\ToggleForBP.cpp 18  2   Playground

Upvotes: 0

Views: 9807

Answers (1)

Anon Mail
Anon Mail

Reputation: 4770

Change the signature of your function to this:

void AToggleForBP::SwitchOnOff()
{

    UniqueValueBlah = true;
}

Without making it a member function, the compiler thinks it's a global function.

Upvotes: 5

Related Questions