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\$
4
  • \$\begingroup\$ You've shown the code for UZombieHordeGameInstance but your blueprint code references BP_ZombieHordeGameInstance. \$\endgroup\$
    – Rotem
    Dec 29, 2019 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, 2020 at 10:44
  • \$\begingroup\$ I ended up doing a refactor of the code that avoids this. I never actually got to a solution. \$\endgroup\$ Jan 4, 2020 at 3:22
  • \$\begingroup\$ You should try and give your UObject a UPROPERTY - The GC assumes all objects that inherit from UObject have one. Try adding private: UPROPERTY() UQualitySettings* SelfRef = this; in the header file. \$\endgroup\$
    – Natalo77
    May 21, 2020 at 14:24

1 Answer 1

1
\$\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.

\$\endgroup\$
3
  • \$\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\$ Dec 23, 2019 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\$ Dec 23, 2019 at 13:14
  • \$\begingroup\$ I still get the error. \$\endgroup\$ Dec 23, 2019 at 20:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .