Unreal Engine 4.19 C++Undeclared Identifier错误,但它的代码是IS声明的



这也被发布到了Unreal的AnswerHub,但他们的响应速度很慢,我想知道这是Unreal引擎错误还是Visual Studio 2013/C++的一般错误。我想如果这是一个一般错误,那么StackOverflow会指出它

Visual Studio开始在正确检测代码时出现问题,说空函数中有未知符号,然后开始说已经工作的代码中有未声明的标识符,或者"->"未知,等等https://i.stack.imgur.com/fOLRj.png下面是我用来显示问题的代码。当我再次尝试时,它说无法打开ToggleForBP.generated.h

这是Visual Studio 2013的错误还是虚幻引擎的错误

我的.h//在"项目设置"的"说明"页中填写您的版权声明。

#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;

};

我的.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 );
}

我从上面的代码中得到的错误:

Error   2   error : Failed to produce item: D:Unreal ProjectsPlaygroundBinariesWin64UE4Editor-Playground-3827.dll  D:Unreal ProjectsPlaygroundIntermediateProjectFilesERROR   Playground
Error   1   error C2065: 'UniqueValueBlah' : undeclared identifier  D:Unreal ProjectsPlaygroundSourcePlaygroundToggleForBP.cpp 18  1   Playground
Error   3   error MSB3073: The command ""D:ProgramsEpic GamesEpic Games4.9EngineBuildBatchFilesBuild.bat" PlaygroundEditor Win64 Development "D:Unreal ProjectsPlaygroundPlayground.uproject" -rocket -waitmutex" exited with code -1.   C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V120Microsoft.MakeFile.Targets   38  5   Playground
    4   IntelliSense: identifier "UniqueValueBlah" is undefined d:Unreal ProjectsPlaygroundSourcePlaygroundToggleForBP.cpp 18  2   Playground

将函数的签名更改为:

void AToggleForBP::SwitchOnOff()
{
    UniqueValueBlah = true;
}

如果不将其作为成员函数,编译器就会认为它是一个全局函数。

最新更新