daily pastebin goal
23%
SHARE
TWEET

Delegates between two classes - kyleB

orfeasel Sep 3rd, 2016 278 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //In your controller's header file:
  2. private:
  3.  
  4.     DECLARE_DELEGATE_OneParam(MyAwesomeDelegate, FVector)
  5.  
  6.     /** The actual delegate declaration */
  7.     MyAwesomeDelegate MyAwesomeDelegateExecFunc;
  8.  
  9. public:
  10.  
  11.    /** Binds a UFUNCTION
  12.     * @param InUserObject - the object that contains the UFUNCTION
  13.     * @param FuncName - the name of the UFUNCTION (return type: void, parameter: FVector)
  14.     */
  15.     void BindAwesomeDelegateExecutionFunction(UObject* InUserObject, FName FuncName);
  16.  
  17. //In your controller's source file:
  18. void AMyPlayerController::BindAwesomeDelegateExecutionFunction(UObject* InUserObject, FName FuncName)
  19. {
  20.     MyAwesomeDelegateExecFunc.BindUFunction(InUserObject, FuncName);
  21. }
  22.  
  23. //to call the function that is binded to your delegate, somewhere inside your controller's source file type:
  24. MyAwesomeDelegateExecFunc.Execute(AVectorValue);
  25.  
  26. //----------------------------------------------------------------------------------//
  27.  
  28. //Character's header file:
  29. private:
  30.     UFUNCTION()
  31.     ExecutionFunction(FVector AVectorParam);
  32.  
  33.  
  34. //Somewhere inside your character's source file (make sure to include your controller's header file):
  35. AMyPlayerController* Con=Cast<AMyPlayerController>(GetController());
  36.  
  37. Con->BindAwesomeDelegateExecutionFunction(this,FName("ExecutionFunction"));
  38.  
  39. //rest of your logic...
  40.  
  41. void AMyCharacter::ExecutionFunction(FVector AVectorParam)
  42. {
  43.     //the logic that gets executed
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand