虚幻引擎4.19 C ++ Undeclared Identifier错误,但它声明了代码IS

时间:2015-11-07 15:49:12

标签: c++ unreal-engine4 undeclared-identifier

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

基本上没有理由Visual Studio开始在检测代码时遇到问题,说空函数内部有未知符号,然后它开始说已经工作的代码中有未声明的标识符或“ - >”不知道,等等。另一个文件给我这些错误http://i.imgur.com/AVrbdTS.png?1下面是我用来显示我的问题的代码。当我再次尝试时,它说它无法打开 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 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

1 个答案:

答案 0 :(得分:2)

将您的功能的签名更改为:

void AToggleForBP::SwitchOnOff()
{

    UniqueValueBlah = true;
}

不使其成为成员函数,编译器认为它是一个全局函数。