我在虚幻引擎 4 中创建计时器时遇到问题。问题出在 GetWorldTimerManager 中。当我对此调用设置计时器时,我收到 E0070 不完整类型错误。通常这意味着我未能包含某些内容
void ACubeFarmBlock::HandleClicked()
{
if (!bIsPlanted)
{
bIsPlanted = true;
// Change material
BlockMesh->SetMaterial(0, OrangeMaterial);
// Determine when to harvest
GetWorldTimerManager().SetTimer(HarvestTimerHandle, &ACubeFarmBlock::Harvest, HarvestTime,false);
}
}
HarvestTimerHandle 在 header 中定义。 以下是包含的列表。 MyActor.h 包含一个定义 GetWorldTimerManager 的方法,因此我认为我已经包含了所有内容。值得注意的是,当我在线查找计时器函数时,我发现了几个站点,其中此设置计时器方法包含插入在 HarvestTimerHandle 参数和 &ACubeFormBlock::Harvest 参数之间的 this 参数。包括这一点并不会让我的错误消失。
#include "CubeFarmBlock.h"
#include "CubeFarmBlockGrid.h"
#include "UObject/ConstructorHelpers.h"
#include "Components/StaticMeshComponent.h"
#include "Engine/StaticMesh.h"
#include "Materials/MaterialInstance.h"
#include "MyActor.h"
错误:
..\CubeFarmBlock.cpp(76): note: see reference to function template instantiation 'TFunction::TFunction(FunctorType &&)' being compiled 1> with 1> [ 1> FunctorType=void (__cdecl ACubeFarmBlock::* )(float) 1> ]
Severity Code Description Project File Line Suppression State Error (active)
E0070 incomplete type is not allowed CubeFarm ..\CubeFarmBlock.cpp 78 Severity
Code Description Project File Line Suppression State Error (active) E0070
incomplete type is not allowed CubeFarm ..\CubeFarmBlock.cpp 78
最佳答案
在头文件中创建一个处理程序FTimerHandle InputTimeHandle
;
然后在你的cpp文件中
GetWorld()->GetTimerManager().SetTimer(InputTimeHandle,this, &AMyPlayerController::GetInputTimer, 1, true,0.5f);
您只是缺少参数
关于c++ - 在虚幻引擎 C++ 中设置计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44492250/