Announcement

Collapse
No announcement yet.

C++ to Blueprints (and vice-versa): not possible with AHUD ?

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

    C++ to Blueprints (and vice-versa): not possible with AHUD ?

    Hello.

    Is there a reason why BlueprintImplementableEvent don't work (at least, not as easily) with AHUD derived classes ?

    I've tested this on two projects based on the Third-Person Template. First project, I make the calls inside the default character class.

    Header
    Code:
    UCLASS(config=Game)
    class ABPCallsHUDCharacter : public ACharacter
    {
            (...)
    
    	/** Called by Fire() to submit some input to Bluprints */
    	UFUNCTION(BlueprintImplementableEvent, Category=Calls)
     	void MakeBPCall(int32 no);
    
    	 /** Received by Blueprints after a fire event has been launched */
     	UFUNCTION(BlueprintCallable, Category=Calls)
     	void ReceiveBPCall(int32 no);
    };
    Source
    Code:
    void ABPCallsCharacter::Fire()
    {
    	MakeBPCall(666);
    }
    
    void ABPCallsCharacter::ReceiveBPCall(int32 no)
    {
    	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, FString::FromInt(no));
    }
    I mapped an Event to the Fire() button. Here's a BP implementation: Basic stuff: Receive a number, increment by 1, send it back to C++. Works great.

    Click image for larger version

Name:	bpcalls.png
Views:	1
Size:	63.0 KB
ID:	1137267

    However, on a separate project using TPP, I have created a MyHUD class, bound it as default in my GameMode like so:

    Code:
    ABPCallsHUDGameMode::ABPCallsHUDGameMode(const class FPostConstructInitializeProperties& PCIP)
    	: Super(PCIP)
    {
    	// set default pawn class to our Blueprinted character
    	static ConstructorHelpers::FObjectFinder<UClass> PlayerPawnBPClass(TEXT("Class'/Game/Blueprints/MyCharacter.MyCharacter_C'"));
    	if (PlayerPawnBPClass.Object != NULL)
    	{
    		DefaultPawnClass = PlayerPawnBPClass.Object;
    
    	}
    
    	HUDClass = AMyHUD::StaticClass();
    Then I create a blueprint based on AMyHUD.

    Click image for larger version

Name:	myhud.png
Views:	1
Size:	47.8 KB
ID:	1137268

    I made a custom fire function in which my character can reach the HUD and calls the exact kind of function to that was successful on the earlier project. In debug mode, I see the call being traced to my custom fire shot, crossing MakeBPCall() but there is no reaction inside the Blueprint, and, of course, nothing comes out of it either.

    Header
    Code:
    UCLASS()
    class BPCALLSHUD_API AMyHUD : public AHUD
    {
            (...)
    
    	/** Called by Fire() to submit some input to Bluprints */
    	UFUNCTION(BlueprintImplementableEvent, Category=Calls)
    	void MakeBPCall(int32 no);
    
    	/** Received by Blueprints after a fire event has been launched */
    	UFUNCTION(BlueprintCallable, Category=Calls)
    	void ReceiveBPCall(int32 no);
    };
    Source
    Code:
    void AMyHUD::OnFire()
    {
    	MakeBPCall(666);
    }
    
    void AMyHUD::ReceiveBPCall(int32 no)
    {
    	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, FString::FromInt(no));
    }
    Is there some caveat or extra code needed to make it work under AHUD based classes ?

    Cheers.

    #2
    Well, your BP derived hud class isn't being created since your setting HUDClass to the native layer and not the blueprint. BTW, to make that easier, derive a Blueprint class from your gamemode and then you can edit the classes to use in the defaults section. Just remember to make sure that gamemode is set to be the one used

    Comment


      #3
      Ah, ****! Most excellent, Sir! Your answer clears a lot of way:

      1) Now, I also understand why it works out of the box with the TPP template, since the default MyCharacter blueprint is set in the original GameMode.
      2) There is some confusion, I'm sure, for other newbies to Unreal like me, as we derive a C++ class and call it MyHUD (as per suggestion by the Wizard) and create a Blueprint from it called MyHUD (because MyCharacter is right next to it) and only now do I understand why some of the values are grey and others are blue in the drop down.

      Have a very good Friday.

      Comment


        #4
        Glad I could help. I am working on a sample and I'll make sure to call out in my documentation those types of things.

        Comment

        Working...
        X