简体   繁体   English

在虚幻引擎C ++中设置计时器

[英]Setting timers in Unreal Engine C++

I am having trouble creating a timer in Unreal Engine 4. The problem is in GetWorldTimerManager. 我在虚幻引擎4中创建计时器时遇到问题。问题出在GetWorldTimerManager中。 When I call set timer on this I get an E0070 incomplete type error. 当我对此调用set timer时,出现E0070不完整的类型错误。 Normally this means that I have failed to include something 通常这意味着我没有包含一些内容

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 is defined in the header. 标头中定义了HarvestTimerHandle。 Below is the list of includes. 以下是包含项列表。 MyActor.h contains a method that defines GetWorldTimerManager so I think I have included everything. MyActor.h包含定义GetWorldTimerManager的方法,因此我认为我已经包含了所有内容。 It is worth it to note that when I looked the timer function up online I found several sites where this set timer method included a this argument inserted between the HarvestTimerHandle argument and the &ACubeFormBlock::Harvest argument. 值得一提的是,当我在线查看计时器功能时,发现了几个站点,其中此设置计时器方法包括在HarvestTimerHandle参数和&ACubeFormBlock :: Harvest参数之间插入的this参数。 Including this does not make my error go away. 包括这并不能使我的错误消失。

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

The errors: 错误:

..\\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> ] .. \\ CubeFarmBlock.cpp(76):注意:请参见对正在编译的函数模板实例化'TFunction :: TFunction(FunctorType &&)'的引用1>中带有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 E0070不允许使用不完整的类型CubeFarm .. \\ CubeFarmBlock.cpp 78严重性
Code Description Project File Line Suppression State Error (active) E0070 代码说明项目文件行抑制状态错误(活动)E0070
incomplete type is not allowed CubeFarm ..\\CubeFarmBlock.cpp 78 不允许使用不完整的类型CubeFarm .. \\ CubeFarmBlock.cpp 78

In your header file create a handler FTimerHandle InputTimeHandle; 在头文件中,创建一个处理程序FTimerHandle InputTimeHandle;

Then in your cpp file 然后在您的cpp文件中

GetWorld()->GetTimerManager().SetTimer(InputTimeHandle,this, &AMyPlayerController::GetInputTimer, 1, true,0.5f); GetWorld()-> GetTimerManager()。SetTimer(InputTimeHandle,this,&AMyPlayerController :: GetInputTimer,1,true,0.5f);

You are only missing parameters 您只缺少参数

Ok, so for a warning, I've never used UE4, however... 好的,因此,为了警告起见,我从未使用过UE4,但是...

This error says that you are trying to bind a member function to a TFunction: 此错误表明您正在尝试将成员函数绑定到TFunction:

'TFunction::TFunction(FunctorType &&)' being compiled 1> with 1> 
    [ 1> FunctorType=void (__cdecl ACubeFarmBlock::* )(float) 1> ]

Member functions need an Object to point to.. I think you are missing the 'this' parameter. 成员函数需要一个Object指向。.我认为您缺少'this'参数。 Without looking it up, I think you either need to: 如果不查找,我认为您要么需要:

Eg 例如

GetWorldTimerManager().SetTimer(HarvestTimerHandle, this, &ACubeFarmBlock::Harvest, HarvestTime,false);

I can't find any simple references online, but if you search for Member Function pointers and perhaps the hidden this parameter you can get an idea as to what is going wrong. 我在网上找不到任何简单的引用,但是如果您搜索成员函数指针,并且可能隐藏了此参数 ,则可以了解出了什么问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM