User Tag List

Results 1 to 4 of 4

Thread: Adding functions to an event: trouble with specifics

  1. #1

    Adding functions to an event: trouble with specifics

    Hey, so I'm trying to emulate some blueprint event behavior in C++ and am getting stuck on how exactly to handle it. Here's the blueprint:

    Name:  Capture.JPG
Views: 18
Size:  28.0 KB

    So, from within my character class I can call GetSprite()->OnFinishedPlaying.Add, but I'm not sure how to actually set up a function to be passed in.

    In my .h, I'm declaring the function that I want OnFinishedPlaying to call (ATest2DGameCharacter::EndAttack) as a multicast delegate:

    Then, within the character class header I'm declaring the function:

    	void EndAttack();
    From within my .cpp, I then try to add the function to OnFinishedPlaying:
    Obviously I'm handling it wrong though, because the compiler isn't even seeing my function as a delegate.
    Error D:\GameProjects\Test2DGame\Source\Test2DGame\Test2DGameCharacter.cpp(74) : note: No constructor could take the source type, or constructor overload resolution was ambiguous
    Error D:\GameProjects\Test2DGame\Source\Test2DGame\Test2DGameCharacter.cpp(74) : note: Reason: cannot convert from 'void (__cdecl ATest2DGameCharacter::* )(void)' to 'const TScriptDelegate<FWeakObjectPtr>'
    Error D:\GameProjects\Test2DGame\Source\Test2DGame\Test2DGameCharacter.cpp(74) : error C2664: 'void TMulticastScriptDelegate<FWeakObjectPtr>::Add(const TScriptDelegate<FWeakObjectPtr> &)': cannot convert argument 1 from 'void (__cdecl ATest2DGameCharacter::* )(void)' to 'const TScriptDelegate<FWeakObjectPtr> &'
    So, how can I set this up probably?

  2. #2
    Join Date
    Mar 2014
    To clarify you want the EndAttack() function to be called when the GetSprite()->OnFinishedPlaying() Event is called?

  3. #3
    Yup, exactly.

  4. #4
    Join Date
    Mar 2014
    Hmm after looking it up, OnFinishedPlaying isn't the UFUNCTION(BlueprintNativeEvent) I assumed it was.
    I have no idea how to use a FFlipbookFinishedPlaySignature...

    That said, you could declare a C++ function:
    UFUNCTION(BlueprintCallable, Category = "Any Category Name") void CustomOnFinishedPlayingCall();

    You can then connect that function to the OnFinishedPlaying Event in the blueprint.
    Its kind of a loopy work around: (C++)OnFinishedPlaying -> (Blueprint)OnFinishedPlaying -> (C++)CustomOnFinishedPlayingCall()
    But it does technically let you code behavior for that event in C++.

    You can even add returns and arguments to the function with no problems:
    UFUNCTION(BlueprintCallable, Category = "Any Category Name") int32 CustomOnFinishedPlayingCall(float Infloat);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts