{"id":180,"date":"2022-04-17T10:59:17","date_gmt":"2022-04-17T02:59:17","guid":{"rendered":"https:\/\/www.jinhaihan.top\/WordPress\/?p=180"},"modified":"2022-04-17T10:59:18","modified_gmt":"2022-04-17T02:59:18","slug":"ue5-c-timer%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.jinhaihan.top\/WordPress\/ue5-c-timer%e7%9a%84%e4%bd%bf%e7%94%a8\/","title":{"rendered":"UE5 C++ Timer\u7684\u4f7f\u7528"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><p>1.\u521b\u5efa\u4e00\u4e2a<code>FTimerHandle<\/code>\u6765\u7ba1\u7406\u8ba1\u65f6\u5668\uff0c\u4e00\u4e2a\u8ba1\u65f6\u5668\u4e00\u4e2ahandle<\/p>\n<pre><code class=\"language-C++\">FTimerHandle MyTimerHandle;\n<\/code><\/pre>\n<p>2.\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u8ba1\u65f6\u5668\u7ed3\u675f\u4e4b\u540e\u89e6\u53d1\uff1a<\/p>\n<pre><code class=\"language-C++\"> UFUNCTION()\n void OnNext();\n<\/code><\/pre>\n<p>3.\u8bbe\u7f6e\u8ba1\u65f6\u5668\uff1a<\/p>\n<pre><code class=\"language-cpp\">GetWorld()-&gt;GetTimerManager().SetTimer(MyTimerHandle, this, &amp;MyActor::OnExplode, Time, false);\n<\/code><\/pre>\n<p>3.\u6e05\u9664\u8ba1\u65f6\u5668\uff1a<\/p>\n<pre><code class=\"language-cpp\">\/\/\u6e05\u9664\u4e00\u4e2a\nGetWorld()-&gt;GetTimerManager().ClearTimer(MyTimerHandle);\n\/\/\/\u6e05\u9664\u6240\u6709\nGetWorld()-&gt;GetTimerManager().ClearAllTimersForObject(this);\n<\/code><\/pre>\n<p>4.SetTimer\u51fd\u6570\u53c2\u6570\u5b9a\u4e49\uff1a<\/p>\n<pre><code class=\"language-cpp\">\/**\n\t * Sets a timer to call the given native function at a set interval.  If a timer is already set\n\t * for this handle, it will replace the current timer.\n\t *\n\t * @param InOutHandle\t\t\tIf the passed-in handle refers to an existing timer, it will be cleared before the new timer is added. A new handle to the new timer is returned in either case.\n\t * @param InObj\t\t\t\t\tObject to call the timer function on.\n\t * @param InTimerMethod\t\t\tMethod to call when timer fires.\n\t * @param InRate\t\t\t\tThe amount of time (in seconds) between set and firing.  If &lt;= 0.f, clears existing timers.\n\t * @param InbLoop\t\t\t\ttrue to keep firing at Rate intervals, false to fire only once.\n\t * @param InFirstDelay\t\t\tThe time (in seconds) for the first iteration of a looping timer. If &lt; 0.f InRate will be used.\n\t *\/\n\ttemplate&lt; class UserClass &gt;\n\tFORCEINLINE void SetTimer(FTimerHandle&amp; InOutHandle, UserClass* InObj, typename FTimerDelegate::TMethodPtr&lt; UserClass &gt; InTimerMethod, float InRate, bool InbLoop = false, float InFirstDelay = -1.f)\n\t{\n\t\tInternalSetTimer(InOutHandle, FTimerUnifiedDelegate( FTimerDelegate::CreateUObject(InObj, InTimerMethod) ), InRate, InbLoop, InFirstDelay);\n\t}\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":182,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7,13],"tags":[],"class_list":["post-180","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bolg","category-unreal-engine"],"jetpack_publicize_connections":[],"jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.jinhaihan.top\/WordPress\/wp-content\/uploads\/2022\/04\/backiee-212913-scaled.jpg?fit=2560%2C1440&ssl=1","_links":{"self":[{"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/posts\/180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/comments?post=180"}],"version-history":[{"count":1,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/posts\/180\/revisions"}],"predecessor-version":[{"id":183,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/posts\/180\/revisions\/183"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/media\/182"}],"wp:attachment":[{"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/media?parent=180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/categories?post=180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jinhaihan.top\/WordPress\/wp-json\/wp\/v2\/tags?post=180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}