GetClass() vs StaticClass()

ShirtyKezRat
Sat, 12 Dec 2015 17:42:34 +0000
Rendering

Hey,

Decided to dig a little deeper in understanding UProperty’s and UClass’s etc. With this code I’m getting behavior I really don’t understand and I’m wondering if someone could explain this to me:

AUObjectTester::AUObjectTester(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	TestUObject = ObjectInitializer.CreateDefaultSubobject<UTestUObject>(this, TEXT("MyTestUObject"));

	UClass* TestUObjectClass = TestUObject->GetClass();
	UClass* TestUObjectStaticClass = UTestUObject::StaticClass();
	UClass* TestUObjectStaticClassTakenFromGetClass = TestUObject->GetClass()->StaticClass();

	PrimaryActorTick.bCanEverTick = true;
}

Here:

TestUObjectClass is name TestUObject.

TestUObjectStaticClass is name TestUObject

TestUObjectStaticClassTakenFromGetClass is name Class

but here in a function that is called 3 seconds after BeginPlay:

void AUObjectTester::TimedFunction()
{
	UClass* TestUObjectClass = TestUObject->GetClass();
	UClass* TestUObjectStaticClass = UTestUObject::StaticClass();
	UClass* TestUObjectStaticClassTakenFromGetClass = TestUObject->GetClass()->StaticClass();

	bool Test1 = false;
	if (TestUObject->IsA(TestUObject->GetClass()))
	{
		Test1 = true;
	}

	bool Test2 = false;
	if (TestUObject->IsA(UTestUObject::StaticClass()))
	{
		Test2 = true;
	}

	bool Test3 = false;
	if (TestUObject->IsA(TestUObject->GetClass()->StaticClass()))
	{
		Test3 = true;
	}
}

TestUObjectClass is name OnlineSession.

TestUObjectStaticClass is name TestUObject

TestUObjectStaticClassTakenFromGetClass is name Class

Also only test1 one passes.

Is there maybe something wrong with my code?

Do i not understand some kind of difference between what StaticClass() returns and GetClass() returns?

I’ve done a lot of unreal coding and never experienced any problems with checking what a class type an object is with the IsA() method, the behavior here is quite worrying to me and makes me think I don’t understand what is going on.

Anyway very confused and would appreciate some feedback.

6 posts - 1 participant