Announcement

Collapse
No announcement yet.

Adding functions to an event: trouble with specifics

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:

    Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	28.0 KB
ID:	1226724

    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:

    Code:
    DECLARE_MULTICAST_DELEGATE(EndAttack)
    Then, within the character class header I'm declaring the function:

    Code:
    	UFUNCTION()
    	void EndAttack();
    From within my .cpp, I then try to add the function to OnFinishedPlaying:
    Code:
    	GetSprite()->OnFinishedPlaying.Add(&ATest2DGameCharacter::EndAttack);
    Obviously I'm handling it wrong though, because the compiler isn't even seeing my function as a delegate.
    Code:
    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
    To clarify you want the EndAttack() function to be called when the GetSprite()->OnFinishedPlaying() Event is called?

    Comment


    • #3
      Yup, exactly.

      Comment


      • #4
        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);

        Comment

        Working...
        X