Hi,
I am running into a tricky an issue that I cannot understand the cause.
I have the following API Manager class, that is instantiated in my custom Game Instance.
UENUM(BlueprintType)
enum EAPIAuthenticationResponse
{
Success,
InvalidCredentials,
ConnectionFailed,
Error,
};
UCLASS(BlueprintType)
class MYGAME_API UAPIManager : public UObject
{
GENERATED_BODY()
public:
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FAPIAuthenticationResponse, EAPIAuthenticationResponse, AuthenticationResponse);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FAPILoadCharactersResponse);
UAPIManager();
~UAPIManager();
UFUNCTION(BlueprintCallable, Category = "My Game Network")
void StartAuthenticate(FString Email, FString Password);
UPROPERTY(BlueprintAssignable, Category = "My Game Network")
FAPIAuthenticationResponse OnAuthenticationResponse;
UFUNCTION(BlueprintCallable, Category = "My Game Network")
void StartLoadCharacters();
UPROPERTY(BlueprintAssignable, Category = "My Game Network")
FAPILoadCharactersResponse OnLoadCharactersResponse;
};
In Game Instance, I hold a pointer to the manager, and instantiate the manager during Init :
void UMyGameGameInstance::Init()
{
UGameInstance::Init();
m_pAPIManager = NewObject<UAPIManager>(UAPIManager::StaticClass());
}
I can retrieve the object in Blueprints, and call functions on it (like Start Authenticate). But when I try to bind a Blueprint to any delegate in this class, the game crashes with :
Assertion failed: ((UObject*)ContainerPtr)->IsValidLowLevel() [File:D:\Build\++UE4+Licensee\Sync\Engine\Source\Runtime\CoreUObject\Public\UObject/UnrealType.h] [Line: 374]
I have looked there and debugged as much as I can, my object pointer seems valid. What’s even more surprising is I can bind delegates with enumerations on other classes, but not this one. I have noted that with this API Manager class, Blueprint reports the parameter type as “Enumeration”, whereas on other classes, the parameter type to the delegate is “Byte” (implicit conversion). In addition, the Blueprint Editor randomly complains about not finding the signature for the delegate when hot-reloading C++, which can only be fixed by restarting the editor and compiling the blueprint, leading to the aforementioned bug.
I have also noted that this problem started to occur when I relocated the pointer to API Manager from the class itself (it was singleton) to the Game Instance, so that the pointer survives the travel through levels, but I fail to see how that would be related to the bug.
Would anyone have a clue on where I may be wrong ?
Many thanks !