Is it possible to call function defined in blueprint from c++?

Is it possible to call function defined in blueprint from c++?

Maybe it is possible to find a BP function by name in C++ and call it then. I have some other suggestions though:

You could declare a blueprint implementable function in C++ and then define the actual implementation in blueprint:



// You can call MyFunction() in C++, but the implementation is in BP
UFUNCTION(BlueprintImplementableEvent)
void MyFunction();


You could create a multicast delegate in C++ that you can broadcast, that any blueprint can bind events to:



DECLARE_DYNAMIC_MULTICAST_DELEGATE( FMyEventSignature );

// You can call MyEvent.Broadcast(). In blueprint you can bind events to MyEvent which fire when MyEvent.Broadcast() is called in C++.
UPROPERTY(BlueprintAssignable)
FMyEventSignature MyEvent;



Thank you!!!

I have tried the second approach.But i confont a new problem

The head file:
#pragma once
#include “Kismet/BlueprintFunctionLibrary.h”
#include<stdio.h>
#include <iostream>
using namespace std;

#include “MyBlueprintFunctionLibrary.generated.h”

/**
*
*/
UCLASS()
class MYP623_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()

public:
UFUNCTION(BlueprintCallable, Category = “Huanying|Socket”)
static FString StartCollect();

    DECLARE_DYNAMIC_MULTICAST_DELEGATE(FMyEventSignature);
UPROPERTY(BlueprintAssignable)
FMyEventSignature MyEvent;

};

However ,the .cpp file can not recognize MyEvent.

You need to #include whatever file defines FMyEventSignature

If you post some of the error messages that can also help us track down the errors.

I usually put the DECLARE_DYNAMIC_MULTICAST_DELEGATE above UCLASS(), not sure if that matters.

I think your problem is that you’re trying to call a member variable MyEvent in a static function. I would advise using a static function to broadcast a delegate. Instead consider putting the delegate in some central actor class, like your GameMode or GameState and broadcasting via that actor.

I want to pass a parameter,FString or something.What should i do then ?

Try BlueprintNativeEvent if your blueprint is a subclass of the C++ implementation

https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Functions/Specifiers/BlueprintNativeEvent/index.html

I declared the following in MyActor.h
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FNewDataComes, FString, locationData);
UPROPERTY(BlueprintAssignable, Category = “Damage”)
FNewDataComes OnDataUpdated;
Then in MyActor.cpp
I create a thread to receive data from udp socket server.When data comes,this thread will notify blueprint.
DWORD32 WINAPI StartReceiveData(LPVOID myparam)
{

AMyActor* pDlg = (AMyActor*)myparam;
if (pDlg == NULL)
	return 0;

dwSendSize = sizeof(SOCKADDR_IN);
while (true)
{
	char* pszRecv = new char[4096];
	 nRet = recvfrom(sockClient, pszRecv, 4096, 0, (SOCKADDR*)&siRemote, &(dwSendSize));
	if (nRet == SOCKET_ERROR) {
		cout &lt;&lt; "recvfrom Error " &lt;&lt; WSAGetLastError() &lt;&lt; endl;
		FString a;
                 a.AppendInt(WSAGetLastError());
		//a.Append(inet_ntoa(siRemote.sin_addr));
		delete]  pszRecv;
		return -1;
	}
	else if (nRet == 0) {
		 delete]  pszRecv;
	 
	}
	else{
		pszRecv[nRet] = '\0';
		cout &lt;&lt; inet_ntoa(siRemote.sin_addr) &lt;&lt; endl
			&lt;&lt; pszRecv &lt;&lt; endl;
                    pDlg-&gt;OnDataUpdated.Broadcast(pszRecv);
	        delete]  pszRecv;
    }
}
return 0;

}

The data comes very fast.However,the program always crashed after running for a while.Is there any problem in the way i use the delegate?