1 新建MyActor C++类

2 MyActor.h

// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"UCLASS()
class ROTATE_API AMyActor : public AActor
{GENERATED_BODY()public:    // Sets default values for this actor's propertiesAMyActor();protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;public: // Called every framevirtual void Tick(float DeltaTime) override;void RepeatingFunction();FTimerHandle MemberTimerHandle;};

MyActor.cpp

// Fill out your copyright notice in the Description page of Project Settings.#include "MyActor.h"
#include "TimerManager.h"// Sets default values
AMyActor::AMyActor()
{// 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;
}// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{Super::BeginPlay();/*template<class UserClass>void SetTimer(FTimerHandle & InOutHandle,UserClass * InObj,typename FTimerDelegate::TUObjectMethodDelegate< UserClass >::FMethodPtr InTimerMethod,float InRate,bool InbLoop,float InFirstDelay)InOutHandle 是我们要设置的计时器UserClass 调用timer函数的objectInTimerMethod timer会重复执行的方法InRate 调用频率把,例如填0.5f的话,那么InTimerMethod就会每隔0.5f调用一次InbLoop 是否循环,如果是false的那么方法只会执行一次InFirstDelay 第一次调用之前延时的时间,例如5.0f,那么过5秒后,方法才执行,然后才根据InRate 正常调用。*/// 在5秒后 每两秒调用函数RepeatingFunction,循环调用GetWorldTimerManager().SetTimer(MemberTimerHandle, this, &AMyActor::RepeatingFunction, 2.0f, true, 5.0f);//清除定时器//GetWorldTimerManager().ClearTimer(MemberTimerHandle);}// Called every frame
void AMyActor::Tick(float DeltaTime)
{Super::Tick(DeltaTime);
}void AMyActor::RepeatingFunction()
{GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Hello Timer"));
}

3 运行程序可以看到屏幕每两秒打印字符串

ue4 定时器 SetTimer相关推荐

  1. C++中的定时器-SetTimer

    先请看SetTimer这个API函数的原型 [cpp] view plaincopy print? [cpp] view plaincopy print? [cpp] view plaincopy p ...

  2. MFC定时器SetTimer

    什么时候我们需要用到SetTimer函数呢? 当你需要每个一段时间执行一件事的的时候就需要使用SetTimer函数 了. 使用定时器的方法比较简单,通常告诉WINDOWS一个时间间隔,然后WINDOW ...

  3. MFC 的定时器SetTimer

    使用定时器实时显示系统时间 添加静态文本控件 为控件添加变量 界面布局 void CSetTimerDlg::OnTimer(UINT_PTR nIDEvent) {if (nIDEvent == 1 ...

  4. VC++中定时器SetTimer函数的应用总结

    什么时候我们需要用到SetTimer函数呢?当你 需要每个一段时间执行一件事的的时候就需要使用SetTimer函数了.使用定时器的方法比较简单,通常告诉WINDOWS一个时间间隔,然后WINDOWS以 ...

  5. c++ 定时器SetTimer

    本文列举两个例子进行说明. 例 1,  不使用回调函数,是按照时间到后 去响应一个自定义的函数 #include<iostream> #include<Windows.h>us ...

  6. VS2022 VC++下控制台程序SetTimer定时器的应用

    在Vs2022下,应用VC++控制台程序,SetTimer定时器的应用,在很多的介绍例程当中,都使用了 SetTimer(NULL, TimerID, peried, TimerProc); 但是当这 ...

  7. 《MFC游戏开发》笔记五 定时器和简单动画

    本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9332377 作者:七十一雾央 新浪微博:http:// ...

  8. win32 ——定时器消息 小程序:打印时间

    //定时器消息 //设置了定时器之后,操作系统每隔一段相同的时间就产生WM_TIMER消息//原型 UINT_PTR SetTimer(HWND hWnd, //窗口句柄UINT_PTR nIDEve ...

  9. python timer怎么用_python定时器(Timer)用法简单实例

    python定时器(Timer)用法简单实例 本文实例讲述了python定时器(Timer)用法.分享给大家供大家参考.具体如下: # encoding: UTF-8 import threading ...

最新文章

  1. python数据分析基础 余本国_Python数据分析基础
  2. 深入浅出LSTM神经网络
  3. QTP的那些事--web测试脚本不能录制的解决方法(个人整理未完待续)
  4. 通过Shell开发企业级专业服务启动脚本案例(MySQL)
  5. 11g内存管理新特性的internal表现
  6. CentOS tcpdump的使用实例
  7. ssh互相免密登录_linux服务器之间实现ssh免密码登录的方法
  8. Taylor Swift - Mean-pdf
  9. 【upc】Water Testing 皮克定理+多边形面积公式
  10. 中国移动的垃圾短信屏蔽算法?
  11. elementui不生效
  12. GDT陶瓷气体放电管的材质介绍
  13. 百度云for mac破解方法--获取无限svip
  14. JS实现水波涟漪特效
  15. 恩智浦 飞思卡尔Freescale Kinetis KEA128学习笔记3--GPIO模块(二)
  16. 如何在Win10下,清空剪贴板
  17. 二面泛微成都Java岗 (2022.3.23)
  18. STM32摄像头实验
  19. 选择恐惧症终极自救指南
  20. MICCAI 2020 Challenges相关数据集下载

热门文章

  1. Java快速入门-05-数组循环条件 实例《延禧攻略》
  2. Android talkback 盲人模式无法响应问题解决方案
  3. Unity 保存图片到相册以及权限管理
  4. STM8开发实例-初识STM8S207R8
  5. 【echarts】三环环形图,在环形图的每个扇形之间加空隙
  6. Windows 11下安装 nginx
  7. 大学生应该怎样选择路线(桌面应用开发,服务后台,游戏开发)
  8. Directshow 如何获取摄像头音视频设备,并判断摄像头是否占用。
  9. react 配置ant-Mobile
  10. request对象和response对象及使用介绍