[UE4] How to call C++ function from class blueprint?

Hey tgraupmann-

The uint16 data type can be used in code however it is not recognized by blueprints. The only numeric datatypes that are recognized in blueprints are uint8, int32, and float. If you are doing the calculations in code then you could pass in an int32 from the blueprint and then cast to a uint16 in code to work with.

Cheers

I made a video for my C++/BP question.

http://img.youtube.com/vi/a4NlueF948g/0.jpg

I'm trying to get a class blueprint to call my C++ code.

I made a class that extends an AActor.

UCLASS()
class INAPPPURCHASES_API AOuyaSDK : public AActor
{

    /* Tried making a delegate so it appears as a function on the actor in Unreal */
    DECLARE_DELEGATE_RetVal_OneParam(bool, OuyaGetAnyButtonDelegate, uint16)
    OuyaGetAnyButtonDelegate OuyaGetAnyButtonHandler;

    /* Check if the OUYA Button is pressed, true when pressed */
    UFUNCTION(BlueprintNativeEvent, Category = OUYA)
    bool OuyaGetAnyButton(uint16 button);
}

In my cpp implemented the function.

bool AOuyaSDK::OuyaGetAnyButton_Implementation(uint16 button)
{
    return false;
}

And in the constructor, bind the function.

AOuyaSDK::AOuyaSDK(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
{
    OuyaGetAnyButtonHandler.BindUFunction(this, "OuyaGetAnyButton");
}

Adding a custom event or just being able to invoke “OuyaGetAnyButton” doesn’t seem to be working for me…

I changed my arguments to an int32 but still in the Blueprint dialog “call functions on OuyaSDK” I’m still not seeing the function listed.

I recompiled C++ and recompiled the blueprint. I’m missing something???

	DECLARE_DELEGATE_RetVal_OneParam(bool, OuyaGetAnyButtonDelegate, int32)
	OuyaGetAnyButtonDelegate OuyaGetAnyButtonHandler;

	// Check if the OUYA Button is pressed, true when pressed
	UFUNCTION(BlueprintNativeEvent, Category = OUYA)
	bool OuyaGetAnyButton(int32 button);

and then implementation:

AOuyaSDK::AOuyaSDK(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	OuyaGetAnyButtonHandler.BindUFunction(this, "OuyaGetAnyButton");
}

bool AOuyaSDK::OuyaGetAnyButton_Implementation(int32 button)
{
	return false;
}

Looking at your video are you able to see the function if you uncheck the context sensitive box in the top-right corner of the right click menu in blueprints? In the MyBlueprint panel you may need to turn on “Show inherited variables.”

When I uncheck “context sensitive” I don’t see the methods appear in the level blueprint or class blueprint.

In “My Blueprint” on the left I see the methods listed. Are you supposed to use “Implement Function” and then force it to invoke the parent? Because I tried that before which crashes the editor. I want to invoke the C++ function vs overriding it. If I wanted to override IIRC I’d use a BlueprintImplementableFunction…

BlueprintCallable is what I was looking for. Thanks!

Problem solved! Now it shows in the class blueprint and level blueprint.

(cookie for !)

If you are trying to invoke the function rather than override then in the UFUNCTION() declaration you want to use BlueprintCallable rather than BlueprintNativeEvent. If you then create a blueprint based on that class you should be able to add the node to the blueprint.