x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

UDelegateFunction as parameter

Hi guys, I'm currently implementing an event manager (which is not in the scene, it's pure c++) that must call blueprints events / functions. What seemed the most easy to use was a function pointer on a function created in cpp. The issue with this is that in our project (currently a student) our gamedesigners have to be able to create their own blueprints that will be called by the event manager.

I'm not used to UE, so there's maybe an issue with what's next.

With that, I assumed I had to use unreal's delegate (so it's blueprintcallable). Since I cant pass DelegateName as a function parameter, where DelegateName is defined like this : Code:

 DECLARE_DELEGATE(DelegateName);

I assumed I'd finally have to use UDelegateFunction* as a parameter. But, the issue is : when I do this :

 void AManagerInterface::EM_ListenEvent(FString _eventName, UDelegateFunction* _delegate, AActor* _actor)
 {
     _actor->_delegate();
 }

it doesnt compile.

I guess there's a point I missed (maybe declare the function pointer's type somewhere or something else).

Full code below (I Hope you dont have to read it to find the issue I currently have)

ManagerInterface.h :

 #pragma once
 
 #include "GameFramework/Actor.h"
 #include "ManagerInterface.generated.h"
 
 DECLARE_DELEGATE(EventDelegate);
 
 UCLASS()
 class ALCATRAZ_API AManagerInterface : public AActor
 {
     GENERATED_BODY()
     
 
 protected:
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
 
     virtual void EndPlay(EEndPlayReason::Type _reason);
 
 public:    
 
     AManagerInterface();
 
     virtual void Tick(float DeltaTime) override;
 
     
     UFUNCTION(BlueprintCallable)
         void EM_CallEvent(FString _eventName);
 
     UFUNCTION(BlueprintCallable)
         void EM_ListenEvent(FString _eventName, UDelegateFunction* _delegate, AActor* _actor);
 
     UFUNCTION(BlueprintCallable)
         void EM_StopListeningEvent(UObject* _pObject);
 
     UFUNCTION(BlueprintCallable)
         void ResetManagers();
 
 };

ManagerInterface.cpp

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "Alcatraz.h"
 #include "ManagerInterface.h"
 
 #include "LevelManager/LevelManager.h"
 #include "EventManager/EventManager.h"
 #include "SaveManager/SaveManager.h"
 
 
 // Sets default values
 AManagerInterface::AManagerInterface()
 {
      // 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 AManagerInterface::BeginPlay()
 {
     Super::BeginPlay();
     
 }
 
 void AManagerInterface::EndPlay(EEndPlayReason::Type _reason)
 {
     ResetManagers();
 }
 
 // Called every frame
 void AManagerInterface::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
 }
 
 //Call an event with it's name
 void AManagerInterface::EM_CallEvent(FString _eventName)
 {
     Singleton<EventManager>::Instance().CallEvent(_eventName);
 }
 
 void AManagerInterface::EM_ListenEvent(FString _eventName, UDelegateFunction* _delegate, AActor* _actor)
 {
     _delegate();
 }
 
 //Indicate that the aactor stops listening. This is mandatory when you destroy an aactor that listen to an event
 void AManagerInterface::EM_StopListeningEvent(UObject* _pObject)
 {
     Singleton<EventManager>::Instance().StopListening(_pObject);
 }
 
 
 //Mandatory on a level reset on on a stop play
 void AManagerInterface::ResetManagers()
 {
     Singleton<EventManager>::Instance().Reset();
     Singleton<LevelManager>::Instance().Reset();
 }

The interesting function here is ListenEvent

I couldnt fine any help yet, that's why I post it here. If there's already a thread about it, I apologize but I didnt found it yet.

Thanks, Arkhain

Product Version: UE 4.15
Tags:
more ▼

asked Apr 14 '17 at 02:22 PM in C++ Programming

avatar image

Arkh4in
21 1 3 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Ok, so I searched a lot about this issue and the answer seem to be that you cant use UE delegates as functions parameter in order to link an event/ function to an input of a blueprintcallable function.

If anyone prove this wrong I'd be thankful but for now, I implemented a full blueprint EventManager using the event dispatcher to solve this.

more ▼

answered Apr 22 '17 at 08:17 AM

avatar image

Arkh4in
21 1 3 5

avatar image Keenan Jun 17 '19 at 05:17 PM

Is this confirmed?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question