Accessing a Blueprints variables derived from a C++ class in a different C++ class

Hey all I am rather a beginner but trying to get better at coding in C++ for UE4. I am trying to access a Blueprints properties that are derived from a C++ class. So for example I have:

int SomeNumber;

in the first class and then made a Blueprint based off this class. Then in my second class I have a reference to the Blueprint using:

UPROPERTY(EditAnywhere, Category = "OtherObject")
		TSubclassOf<AOtherObject> OtherObjectBP;

I have been able to spawn instances of this OtherObjectBP but in my .CPP file of this class I would like to access the variables of OtherObjectBP and can’t seem to figure out. I had assumed it would just be
OtherObjectBP->SomeNumber;
but that doesn’t work. Also if I am completely thinking about this the wrong way please point it out I have been working on code for a bit now so I may just be missing the obvious. Thanks in advance.

After some fiddling I was able to access the variable I want but only after creation. So I’m now trying to find a way to do it without having to spawn the object before hand.

if (OtherObjectBP)
	{
		UWorld* const World = ();
		if (World)
		{
			AThisObjectClass* SO = World->SpawnActor<AOtherObject>(OtherObjectBP, FVector(-390.0f, 280.0f, 180.0f), FRotator(0.0f, 0.0f, 0.0f));
			int32 test = SO->SomeNumber;
			UE_LOG(LogTemp, Warning, TEXT("Catch Rate: %d"), test);
		}
	}

Object need to be create first in order to be in memory, it normal thing in any language. Also remember that Blueprints are classes not objects same as C++.

What you trying to access is defaults and those are stored in reflection system inside UClass object identifying the class (you UClass object to spawn object, in you case it’s stored in OtherObjectBP , TSubclassOf is just special template that limits class selection to specific class relation). It kind of keep in special stagnating object called Class Default Object (CDO) and you can access it from this function:

1 Like

Thank you for the explanation!