# What is the difference between GetClass() and StaticClass()?

**URL:** <https://forums.unrealengine.com/t/what-is-the-difference-between-getclass-and-staticclass/383062>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [January 26, 2017, 8:01pm UTC](https://forums.unrealengine.com/t/what-is-the-difference-between-getclass-and-staticclass/383062 "2017-01-26T20:01:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_3d10c415](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3d10c415](https://forums.unrealengine.com/u/anonymous_user_3d10c415)\
**Post date:** [January 26, 2017, 8:01pm UTC](https://forums.unrealengine.com/t/what-is-the-difference-between-getclass-and-staticclass/383062/1 "2017-01-26T20:01:22Z")

</div>

For example, if I want to spawn an actor one of input parameters is UClass_class.  
I can assign what class to spawn two different ways, by ABomb_ BombClass-\>GetClass() and ABomb::StaticClass()  
As I can tell, the first one creates instance, the other doesn’t, can somebody confirm me that?  
And what about performance? Which should I use?

---

<div class="post-metadata">

**Author:** ![Steve\_Robb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Steve\_Robb](https://forums.unrealengine.com/u/Steve_Robb)\
**Post date:** [January 27, 2017, 11:38am UTC](https://forums.unrealengine.com/t/what-is-the-difference-between-getclass-and-staticclass/383062/2 "2017-01-27T11:38:46Z")

</div>

Hi,

UType::StaticClass() returns the class for UType, whereas Obj-\>GetClass() returns the class for whichever type Obj was created as, even if you’re calling it through a base pointer.

For example:

```
AMyActor* ActorPtr = NewObject<AMyActor>(...);
UObject* ObjPtr = Actor;

UClass* MyActorClass = AMyActor::StaticClass(); // AMyActor
UClass* ObjectClass = UObject::StaticClass(); // UObject
UClass* ActorPtrClass = ActorPtr->GetClass(); // AMyActor
UClass* ObjPtrClass = ObjPtr->GetClass(); // AMyActor

```

Hope this helps,

Steve

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3d10c415](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3d10c415](https://forums.unrealengine.com/u/anonymous_user_3d10c415)\
**Post date:** [January 27, 2017, 2:00pm UTC](https://forums.unrealengine.com/t/what-is-the-difference-between-getclass-and-staticclass/383062/3 "2017-01-27T14:00:00Z")

</div>

ahh I see, so UType::StaticClass() is definite, while Obj-\>GetClass() can be dynamic, since pointer can be reassigned to different object. Thanks man!

---

<div class="post-metadata">

**Author:** ![Ch3shireCat](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ch3shireCat](https://forums.unrealengine.com/u/Ch3shireCat)\
**Post date:** [January 28, 2017, 7:12pm UTC](https://forums.unrealengine.com/t/what-is-the-difference-between-getclass-and-staticclass/383062/4 "2017-01-28T19:12:12Z")

</div>

That’s how polymorphism and virtual functions work. Suppose we have following classes:

```
class A{
public:
    int fun(){return 1;}
};
class B : public A{ //B inherits from A
public:
    int fun(){return 2;} //hides A::fun method
};

int main(){
    A* a = new A; 
    A* b = new B;
    B* c = (B*)b;
    a->fun(); //returns 1
    b->fun(); //still returns 1
    c->fun(); //returns 2!
}

```

But when I add virtual before int fun() in class A body, `b->fun()` will return 2 instead of 1. Magic! 😃

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3d10c415](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3d10c415](https://forums.unrealengine.com/u/anonymous_user_3d10c415)\
**Post date:** [January 28, 2017, 7:23pm UTC](https://forums.unrealengine.com/t/what-is-the-difference-between-getclass-and-staticclass/383062/5 "2017-01-28T19:23:43Z")

</div>

yeah i got that, virtual can be overridden by their child class  
anyways, thanks man, appreciate it. it can get messy starting with lots of info and not knowing what to implement
