{"id":7323,"date":"2023-01-24T08:25:14","date_gmt":"2023-01-24T06:25:14","guid":{"rendered":"https:\/\/store.algosyntax.com\/?post_type=asx-lms-tutorial-cpt&#038;p=7323"},"modified":"2026-03-10T00:09:11","modified_gmt":"2026-03-09T22:09:11","slug":"ue5-how-to-make-tickable-objects","status":"publish","type":"asx-lms-tutorial-cpt","link":"https:\/\/store.algosyntax.com\/tutorials\/unreal-engine\/ue5-how-to-make-tickable-objects\/","title":{"rendered":"UE5 How to make Tickable Objects"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"7323\" class=\"elementor elementor-7323\" data-elementor-post-type=\"asx-lms-tutorial-cpt\">\n\t\t\t\t<div class=\"elementor-element elementor-element-6eda56d e-flex e-con-boxed e-con e-parent\" data-id=\"6eda56d\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-849bc05 elementor-widget elementor-widget-text-editor\" data-id=\"849bc05\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>In Unreal Engine 5 , you can tick any c++ class object. It does not have to be UObject. Here is how you do it:<\/p><ol><li>Have your class inherit from the FTickableGameObject class.<\/li><li>Override the virtual function &#8220;Tick&#8221; in your class.<\/li><li>In the &#8220;Tick&#8221; function, implement the logic that should be executed each tick.<br \/><br \/><br \/><\/li><\/ol><p>That&#8217;s basically it. But let&#8217;s show a code example on how to make C++ Classes tick in unreal engine.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-55d195a e-flex e-con-boxed e-con e-parent\" data-id=\"55d195a\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-d681145 elementor-widget elementor-widget-code-highlight\" data-id=\"d681145\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>class MyTickableClass : public FTickableGameObject\r\n{\r\n\r\nprivate:\r\n\t\/\/ Track The last frame number we were ticked.\r\n\tuint32 LastTickFrame = INDEX_NONE;\r\n\r\npublic:\r\n    \r\n\r\nvirtual void Tick(float DeltaTime) override\r\n{\r\n    \/\/ Implement the logic that should be executed each tick\r\n    \r\n    if ( LastTickFrame == GFrameCounter )\r\n\treturn;\r\n\r\n    \/\/ Do our tick\r\n\t\/\/ ...\r\n\r\n    LastTickFrame = GFrameCounter;\r\n}\r\n\r\n\r\n\r\nvirtual ETickableTickType GetTickableTickType() const override\r\n{\r\n\treturn ETickableTickType::Always;\r\n}\r\n\r\nvirtual TStatId GetStatId() const override\r\n{\r\n    RETURN_QUICK_DECLARE_CYCLE_STAT(MyTickableClass, STATGROUP_Tickables);\r\n}\r\n};\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-eea9611 elementor-widget elementor-widget-heading\" data-id=\"eea9611\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Should we keep track of the last frame we ticked? is it necessary?<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-55b8008 elementor-widget elementor-widget-text-editor\" data-id=\"55b8008\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>It is possible that a tickable object&#8217;s <code>Tick<\/code> function could be called multiple times in the same frame so to be on the safe side and ensure we only tick once, it&#8217;s wise to ensure we only tick once per frame by checking our counter. We do this by enlisting the help of the GFrameCounter variable.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4d4d277 elementor-widget elementor-widget-heading\" data-id=\"4d4d277\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">What is GFrameCounter?<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-370c70e elementor-widget elementor-widget-text-editor\" data-id=\"370c70e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p><code>GFrameCounter<\/code> is a global variable in Unreal Engine that holds the current frame number. It is incremented every frame and can be used to keep track of the current frame number in your game.<\/p><p>\u00a0<\/p><p>When you use <code>GFrameCounter<\/code> in your <code>Tick<\/code> function, you&#8217;re storing the current frame number so that you can compare it with the last frame number ticked in your <code>IsTickable<\/code> function. This way you can ensure that the tick function is only executed once per frame.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-0355f92 e-flex e-con-boxed e-con e-parent\" data-id=\"0355f92\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-6182627 elementor-widget elementor-widget-heading\" data-id=\"6182627\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">What does GetTickableTickType function do?<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cafcaf0 elementor-widget elementor-widget-text-editor\" data-id=\"cafcaf0\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>The <code>FTickableGameObject<\/code> class has a virtual function <code>GetTickableTickType<\/code> which you can override to specify how often your class should be ticked. The default value is <code>ETickableTickType::Always<\/code>, which means that the class will be ticked every frame.<br \/><br \/>You have several options for the tick type (Always,Conditional,Never) that you can pick based on the needs of your class.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bcaf871 elementor-widget elementor-widget-heading\" data-id=\"bcaf871\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">What about ETickableTickType::Conditional<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a651fba elementor-widget elementor-widget-text-editor\" data-id=\"a651fba\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>When a tickable object is set to <code>ETickableTickType::Conditional<\/code>, it means that the object&#8217;s <code>IsTickable<\/code> function will be called to determine if the object should be ticked or not. If the <code>IsTickable<\/code> function returns true, the <code>Tick<\/code> function will be called. If it returns false, the <code>Tick<\/code> function will not be called.<\/p><p>\u00a0<\/p><p>The <code>IsTickable<\/code> function is a virtual function in <code>FTickableGameObject<\/code> that you can override in your class to check the state of your object and determine if it should be ticked or not. This function is called before the <code>Tick<\/code> function, so you can use it to control when your object should be ticked.<\/p><p>\u00a0<\/p><p><code>ETickableTickType::Conditional<\/code> is useful in cases where you only want your object to be ticked when certain conditions are met, or if you want to save CPU time by not ticking an object that doesn&#8217;t need to be ticked.<\/p><p>\u00a0<\/p><p>Please keep in mind that when using <code>ETickableTickType::Conditional<\/code>, you should make sure that <code>IsTickable<\/code> function is quick and it&#8217;s not doing any heavy computation, otherwise it will have an impact on performance. Also, it&#8217;s worth noting that you can use the <code>ETickableTickType::Conditional<\/code> in conjunction with keeping track of the last frame ticked, to make sure that the object is ticked only once per frame.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-bd40b9a e-flex e-con-boxed e-con e-parent\" data-id=\"bd40b9a\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-743a98e elementor-widget elementor-widget-heading\" data-id=\"743a98e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">The GetStatId function and its purpose<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-55c7db5 elementor-widget elementor-widget-text-editor\" data-id=\"55c7db5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>The <code>GetStatId<\/code> function is used to assign a unique identification for a tickable object. It is part of the <code>FTickableGameObject<\/code> interface and is used by Unreal Engine&#8217;s performance tracking system to collect and display statistics about the performance of tickable objects.<\/p><p>\u00a0<\/p><p>The <code>GetStatId<\/code> function returns a <code>TStatId<\/code> struct, which is a unique identifier for the tickable object. This struct is used internally by Unreal Engine to identify the tickable object and track its performance.<\/p><p>\u00a0<\/p><p>The <code>RETURN_QUICK_DECLARE_CYCLE_STAT<\/code> macro is a shorthand way of creating a unique <code>TStatId<\/code> struct for the tickable object. The first parameter is the name of the class, and the second parameter is the group to which the stat belongs.<\/p><p>\u00a0<\/p><p>It&#8217;s important to keep in mind that the <code>GetStatId<\/code> function is only used for performance tracking purposes and it&#8217;s not required for the correct functioning of your tickable object.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-672e0d1 elementor-widget elementor-widget-heading\" data-id=\"672e0d1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">What is StatGroup_Tickables and what are its alternatives\n<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9b75347 elementor-widget elementor-widget-text-editor\" data-id=\"9b75347\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p><code>STATGROUP_Tickables<\/code> is a predefined constant in Unreal Engine that represents a group of statistics related to tickable objects.<\/p><p>\u00a0<\/p><p>It is used as the second parameter of the <code>RETURN_QUICK_DECLARE_CYCLE_STAT<\/code> macro in the <code>GetStatId<\/code> function to assign a unique identification for a tickable object and to group it with other tickable objects&#8217; statistics.<\/p><p>\u00a0<\/p><p>In the Unreal Engine&#8217;s statistics view, you can filter the statistics by group, and by using <code>STATGROUP_Tickables<\/code>, you will be able to see statistics specifically for your tickable object.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-dcf5971 e-flex e-con-boxed e-con e-parent\" data-id=\"dcf5971\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-cc116c3 elementor-widget elementor-widget-heading\" data-id=\"cc116c3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Conlcusion<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7bf0f53 elementor-widget elementor-widget-text-editor\" data-id=\"7bf0f53\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>We hope this guide helped you get started with making C++ classes tickable in unreal engine without making them AActors or AActorComponents.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"featured_media":0,"template":"","asx-lms-tutorial-categories":[58,45],"asx-lms-tutorial-tags":[46],"class_list":["post-7323","asx-lms-tutorial-cpt","type-asx-lms-tutorial-cpt","status-publish","hentry","asx-lms-tutorial-categories-unreal-c-api","asx-lms-tutorial-categories-unreal-engine","asx-lms-tutorial-tags-cpp","entry"],"acf":[],"_links":{"self":[{"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/asx-lms-tutorial-cpt\/7323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/asx-lms-tutorial-cpt"}],"about":[{"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/types\/asx-lms-tutorial-cpt"}],"version-history":[{"count":0,"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/asx-lms-tutorial-cpt\/7323\/revisions"}],"wp:attachment":[{"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/media?parent=7323"}],"wp:term":[{"taxonomy":"asx-lms-tutorial-categories","embeddable":true,"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/asx-lms-tutorial-categories?post=7323"},{"taxonomy":"asx-lms-tutorial-tags","embeddable":true,"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/asx-lms-tutorial-tags?post=7323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}