0
\$\begingroup\$

I have a class in C++ that I want to access in BP. It appears to be fine in C++ but in BP I get Accessed None errors when I try to use it in BP. Here is the class declaration that I am trying to use in BP

UCLASS(BlueprintType)
class ZOMBIEHORDE_API UQualitySettings : public UObject
{
    GENERATED_BODY()

public:

    // constructors

    UQualitySettings();

    // class functions and properties
};

I am holding on to it in the GameInstance as below so I can access it through the GameInstance reference.

CLASS(Blueprintable)
class ZOMBIEHORDE_API UZombieHordeGameInstance : public UGameInstance
{
    GENERATED_BODY()

public:

    UZombieHordeGameInstance();

    UPROPERTY(BlueprintReadOnly, Category = "Zombie Game Instance")
    UQualitySettings *QualitySettings = nullptr;
};

And GameInstance .cpp

UZombieHordeGameInstance::UZombieHordeGameInstance()
{
    QualitySettings = NewObject<UQualitySettings>();
    ensure(QualitySettings);// this passes and does not throw an error
}

This shows how I am accessing it in a widget blueprint.

enter image description here

So how can it be that accessing QualitySettings in BP is None?

\$\endgroup\$
  • \$\begingroup\$ You've shown the code for UZombieHordeGameInstance but your blueprint code references BP_ZombieHordeGameInstance. \$\endgroup\$ – Rotem Dec 29 '19 at 1:12
  • \$\begingroup\$ Have you tried pulling a Print String off of the Cast Failed execution pin of the Cast to BP_ZombieHordeGameInstance. It may be that it's not even getting that far when trying to call the Quality Settings \$\endgroup\$ – Stephen Jan 3 at 10:44
  • \$\begingroup\$ I ended up doing a refactor of the code that avoids this. I never actually got to a solution. \$\endgroup\$ – Jason Crosby Jan 4 at 3:22
0
\$\begingroup\$

Perhaps the reflection system doesn't like the

UPROPERTY(BlueprintReadOnly, Category = "Zombie Game Instance") 
UQualitySettings *QualitySettings = nullptr; //try to remove the = nullptr from here.

Generally in UE4 we set the variables in constructor because of CDO and reflection system on-behalf.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ I'll try but I would think since I'm setting the QualitySettings variable in the constructor and test its valid by calling ensure on it, that BP would see it as not nullptr anymore. Although I do know UE4 has a way of doing things sometimes that doesnt seem logical lol. I'll try it and see what happens. \$\endgroup\$ – Jason Crosby Dec 23 '19 at 12:53
  • \$\begingroup\$ It was just a suggestion, although there is probably a reason noone uses the assign operator in var/property declaration (no where in UE4source as well). \$\endgroup\$ – ColdSteel Dec 23 '19 at 13:14
  • \$\begingroup\$ I still get the error. \$\endgroup\$ – Jason Crosby Dec 23 '19 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.