a_b_75
(a_b_75)
1
Hello,
Working with UE 5.0.3, I’m trying to expose a delegate so it can be assigned through blueprints.
Here’s my code:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameSession.h"
#include "Interfaces/OnlineSessionInterface.h"
#include "NetworkHelperGameSession.generated.h"
/**
*
*/
UCLASS(BlueprintType, Blueprintable)
class NETWORKHELPER_API ANetworkHelperGameSession : public AGameSession
{
GENERATED_BODY()
public:
ANetworkHelperGameSession() : AGameSession(), _enable_register_server( true ) {}
void RegisterServer() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="NetworkHelperGameSession")
bool _enable_register_server;
UPROPERTY(BlueprintAssignable, Category = "NetworkHelperGameSession") // <----- this line fails
FOnStartSessionCompleteDelegate _on_start_session_complete;
};
At build time, UHT fails with the following error:
Unrecognized type 'FOnStartSessionCompleteDelegate' - type must be a UCLASS, USTRUCT, UENUM, or global delegate.
Commenting out the line marked in the above source gets the code to compile, but my delegate won’t be exposed.
I found this topic with a similar issue, but the suggested fix doesn’t work for me: Exposing delegates for blueprints
What am I doing wrong?
Though I doubt it, this may be relevant to my issue: the current class is not compiled inside my projects main module but as part of an extra module.
3dRaven
(3dRaven)
2
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameSession.h"
#include "NetworkHelperGameSession.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnStartSessionCompleteDelegate);
/**
*
*/
UCLASS(BlueprintType, Blueprintable)
class NETWORKHELPER_API ANetworkHelperGameSession : public AGameSession
{
GENERATED_BODY()
public:
void RegisterServer() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "NetworkHelperGameSession")
bool _enable_register_server;
UPROPERTY(BlueprintAssignable, Category = "NetworkHelperGameSession")
FOnStartSessionCompleteDelegate _on_start_session_complete;
};
a_b_75
(a_b_75)
3
Thanks 3dRaven for your reply.
However, I don’t understand the reasons behind your proposed modifications to my code.
I want to use FOnStartSessionCompleteDelegate as declared in Interfaces/OnlineSessionInterface.h :
DECLARE_MULTICAST_DELEGATE_TwoParams(FOnStartSessionComplete, FName, bool);
typedef FOnStartSessionComplete::FDelegate FOnStartSessionCompleteDelegate;
Isn’t that possible? If not, why?
a_b_75
(a_b_75)
5
Alright, I think I got what 3dRaven means.
The delegate declared in OnlineSessionInterface.h is not declared as a dynamic delegate. Only dynamic delegates can be exposed to blueprint.
I have to declare my own dynamic delegate with the same signature as follows.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameSession.h"
#include "NetworkHelperGameSession.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FDynamicOnStartSessionComplete, FName, name, bool, success);
/**
*
*/
UCLASS(BlueprintType, Blueprintable)
class NETWORKHELPER_API ANetworkHelperGameSession : public AGameSession
{
GENERATED_BODY()
public:
ANetworkHelperGameSession() : AGameSession(), _enable_register_server( true ) {}
void RegisterServer() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="NetworkHelperGameSession")
bool _enable_register_server;
UPROPERTY(BlueprintAssignable, Category = "NetworkHelperGameSession")
FDynamicOnStartSessionComplete _on_start_session_complete;
};```
1 Like
3dRaven
(3dRaven)
6
Traditionally you declare the delegate outside of the class. (somewhere under your .generated include and your class definition)
I’m not sure if it will not be cut off by scoping if you put it inside the class definition. All unreal docs have it at the very top.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameSession.h"
#include "NetworkHelperGameSession.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FDynamicOnStartSessionComplete, FName, name, bool, success);
/**
*
*/
UCLASS(BlueprintType, Blueprintable)
class DGP_API ANetworkHelperGameSession : public AGameSession
{
GENERATED_BODY()
public:
ANetworkHelperGameSession() : AGameSession(), _enable_register_server(true) {}
void RegisterServer() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "NetworkHelperGameSession")
bool _enable_register_server;
UPROPERTY(BlueprintAssignable, Category = "NetworkHelperGameSession")
FDynamicOnStartSessionComplete _on_start_session_complete;
};
1 Like
a_b_75
(a_b_75)
7
Thanks a lot!
I’ll edit my solution to take this into account.