{"id":3422,"date":"2022-05-23T12:37:47","date_gmt":"2022-05-23T10:37:47","guid":{"rendered":"https:\/\/store.algosyntax.com\/?post_type=asx-lms-tutorial-cpt&#038;p=3422"},"modified":"2026-03-09T19:37:20","modified_gmt":"2026-03-09T17:37:20","slug":"ue5-pointer-to-delegate-as-class-variable","status":"publish","type":"asx-lms-tutorial-cpt","link":"https:\/\/store.algosyntax.com\/tutorials\/unreal-engine\/ue5-pointer-to-delegate-as-class-variable\/","title":{"rendered":"UE5 Pointer To Delegate As Class Variable"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"3422\" class=\"elementor elementor-3422\" data-elementor-post-type=\"asx-lms-tutorial-cpt\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-a274bd6 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"a274bd6\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-7a1a44c\" data-id=\"7a1a44c\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-b74941a elementor-widget elementor-widget-heading\" data-id=\"b74941a\" 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\"> You Cannot Set A Member Variable As A Pointer To A Delegate<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d07b19e elementor-widget elementor-widget-text-editor\" data-id=\"d07b19e\" 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>Almost all the time, you want a reference to <a href=\"https:\/\/docs.unrealengine.com\/4.27\/en-US\/ProgrammingAndScripting\/ProgrammingWithCPP\/UnrealArchitecture\/Delegates\/\" target=\"_blank\" rel=\"noopener\">unreal engine delegates<\/a>, not a copy. At this point you may have tried and attempted to do something like:<\/p><p>UPROPERTY()<\/p><p><strong>FSomeDelegate* delegatePtr;<\/strong><\/p><p>Or<\/p><p><strong>FSomeDelegate&amp; delegateRef;<\/strong><\/p><p>\u00a0<\/p><p>This will not work and Visual Studio will have warned you even before building or as building errors. Specifically for the Pointer type, You may get the error:\u00a0<\/p><p>\u00a0<\/p><p><strong>cannot have an exposed pointer to this type.<\/strong><\/p><p>\u00a0<\/p><p>and for the reference method , you may get a build error saying something along the lines of:\u00a0<\/p><p>\u00a0<\/p><p><strong>references must be initialized.<\/strong><\/p><p>\u00a0<\/p><p>That is because in c++ a reference needs to be set at declaration.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5d9e14d elementor-widget elementor-widget-heading\" data-id=\"5d9e14d\" 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 Workaround<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5224a1e elementor-widget elementor-widget-text-editor\" data-id=\"5224a1e\" 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>A solution that often works is to get a pointer to the UObject* that contains the unreal engine delegate. The downside is you will need to go through this UObject* to access the delegate every time in code but it&#8217;s a small tradeoff. Here is an example of calling the Broadcast function through the UObject.<\/p><p><strong>UObject-&gt;DelegateVariable.Broadcast()<\/strong><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\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-3422","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\/3422","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\/3422\/revisions"}],"wp:attachment":[{"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/media?parent=3422"}],"wp:term":[{"taxonomy":"asx-lms-tutorial-categories","embeddable":true,"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/asx-lms-tutorial-categories?post=3422"},{"taxonomy":"asx-lms-tutorial-tags","embeddable":true,"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/asx-lms-tutorial-tags?post=3422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}