# \[BP\] Whats the difference between variable of class and object?

**URL:** <https://forums.unrealengine.com/t/bp-whats-the-difference-between-variable-of-class-and-object/292830>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [September 4, 2014, 1:29am UTC](https://forums.unrealengine.com/t/bp-whats-the-difference-between-variable-of-class-and-object/292830 "2014-09-04T01:29:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Makotech222](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Makotech222](https://forums.unrealengine.com/u/Makotech222)\
**Post date:** [September 4, 2014, 1:29am UTC](https://forums.unrealengine.com/t/bp-whats-the-difference-between-variable-of-class-and-object/292830/1 "2014-09-04T01:29:40Z")

</div>

When i add a variable to my blueprint, and set the type to something like UserWidget, there are two options: Object\_UserWidget or Class\_UserWidget. What are the differences between the two? and why aren’t they interchangeable?

---

<div class="post-metadata">

**Author:** ![Dartanlla](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dartanlla/32/724052_2.png) [@Dartanlla](https://forums.unrealengine.com/u/Dartanlla)\
**Post date:** [September 4, 2014, 1:45pm UTC](https://forums.unrealengine.com/t/bp-whats-the-difference-between-variable-of-class-and-object/292830/2 "2014-09-04T13:45:06Z")

</div>

To understand classes and objects you have to understand a little bit about object oriented programming (OOP). A class is just a type. An Object is an instance of that Class which is defined by the type.

Here is one way to think of it. Say you have the plans to build a brand new 2015 Corvette (my next car). What you have is a Class. You don’t have the car you just have the plans to build one. When you instantiate (fancy programming term for build) a Class, you build the Corvette using the plans and you get an Object which is an instance of that Class. So the Object is a real Corvette that you built that actually exists. You can use a Class (the plans) to build as many Objects (the actual car) as you want. This is why the two are not interchangeable. Hope this helps!

---

<div class="post-metadata">

**Author:** ![Makotech222](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Makotech222](https://forums.unrealengine.com/u/Makotech222)\
**Post date:** [September 4, 2014, 3:15pm UTC](https://forums.unrealengine.com/t/bp-whats-the-difference-between-variable-of-class-and-object/292830/3 "2014-09-04T15:15:57Z")

</div>

Yes, i understand OOP very well, but i don’t understand how you can have a variable of the class, rather than the instance. Can you write it in C++ terms? because,

```
Baseperson b;
b = new BasePerson();

```

b is a variable of object. how do i get a variable of a class? In what case would i need it in UE4 blueprint?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_99b84783](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_99b84783](https://forums.unrealengine.com/u/anonymous_user_99b84783)\
**Post date:** [September 4, 2014, 3:24pm UTC](https://forums.unrealengine.com/t/bp-whats-the-difference-between-variable-of-class-and-object/292830/4 "2014-09-04T15:24:58Z")

</div>

You can use classes variables if you want to create an object which class is decided at runtime. In C++ you could have a UClass\* variable, and construct an object based on it.

Example: You want to spawn a sword on a character, but there are multiple sword classes to choose from. You can set the class in the properties, and spawn the sword instance based on it.

---

<div class="post-metadata">

**Author:** ![Dartanlla](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dartanlla/32/724052_2.png) [@Dartanlla](https://forums.unrealengine.com/u/Dartanlla)\
**Post date:** [September 4, 2014, 6:40pm UTC](https://forums.unrealengine.com/t/bp-whats-the-difference-between-variable-of-class-and-object/292830/5 "2014-09-04T18:40:39Z")

</div>

Here is an example of where you might use a Class variable in blueprints:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

Notice the dark purple input pin on the Create node. That pin is expecting a class variable. Also, notice that in C++ that equates to TSubclassOf UObject. This idea of class variables is something Epic came up with for UE4 and this is not a built in system in C++.

---

<div class="post-metadata">

**Author:** ![Makotech222](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Makotech222](https://forums.unrealengine.com/u/Makotech222)\
**Post date:** [September 4, 2014, 8:11pm UTC](https://forums.unrealengine.com/t/bp-whats-the-difference-between-variable-of-class-and-object/292830/6 "2014-09-04T20:11:53Z")

</div>

Ah thank you. That’s what i wanted to hear. I didn’t understand it because its not a C++ thing, but a UE4 thing. And I’ve been using that blueprint node for a while and never released what it was taking.

---

<div class="post-metadata">

**Author:** ![morness](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@morness](https://forums.unrealengine.com/u/morness)\
**Post date:** [October 20, 2014, 8:55pm UTC](https://forums.unrealengine.com/t/bp-whats-the-difference-between-variable-of-class-and-object/292830/7 "2014-10-20T20:55:40Z")

</div>

This is covered in the video tutorials: [Blueprint Essentials: Object and Class Variables | 04 | v4.2 Tutorial Series | Unreal Engine - YouTube](https://www.youtube.com/watch?v=xu7ymhN_7Lo&list=PLZlv_N0_O1gaCL2XjKluO7N2Pmmw9pvhE&index=36)

Basically as far as Blueprint is concerned, if you have something in your scene already and you want to reference it, use an object variable. If you are creating/spawning the object in your variable, then use a class.
