# Static TSubclassOf\<\>

**URL:** <https://forums.unrealengine.com/t/static-tsubclassof/299836>\
**Category:** C++\
**Tags:** unreal-engine, UE4, CPP, question\
**Created:** [November 25, 2014, 3:09pm UTC](https://forums.unrealengine.com/t/static-tsubclassof/299836 "2014-11-25T15:09:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BurnGameVen04\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BurnGameVen04\_1](https://forums.unrealengine.com/u/BurnGameVen04_1)\
**Post date:** [November 25, 2014, 3:09pm UTC](https://forums.unrealengine.com/t/static-tsubclassof/299836/1 "2014-11-25T15:09:48Z")

</div>

In one of my classes, I hold a few class pointers to blueprints in my game. I use the following code to do so:

.h

```
TSubclassOf<class AItem> BlueprintChair;
 TSubclassOf<class AItem> BlueprintLamp;

```

.cpp (In the constructor)

```
static ConstructorHelpers::FObjectFinder<UBlueprint> ChairBlueprint(TEXT("Blueprint'/Game/Item/Chair.Chair'"));
	if (ChairBlueprint.Object)
		BlueprintChair = (UClass*)ChairBlueprint.Object->GeneratedClass;
	
	static ConstructorHelpers::FObjectFinder<UBlueprint> LampBlueprint(TEXT("Blueprint'/Game/Item/Lamp.Lamp'"));
	if (LampBlueprint.Object)
		BlueprintLamp = (UClass*)LampBlueprint.Object->GeneratedClass;

```

The code works fine, but the issue becomes overhead. Every time the class is instanced, it will carry overhead for the two TSubclassOf\<\>. If there was only a few of these objects, that would be okay, but my game has thousands of instances making it unnecessary overhead. Is it possible to make the two TSubclassOf\<\> static objects, and if so, how would I go about doing so? I can’t initialize them as I normally would with static objects because they need to be set in the constructor since I use ConsructorHelpers.

---

<div class="post-metadata">

**Author:** ![BaderThanBad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BaderThanBad](https://forums.unrealengine.com/u/BaderThanBad)\
**Post date:** [November 25, 2014, 3:19pm UTC](https://forums.unrealengine.com/t/static-tsubclassof/299836/2 "2014-11-25T15:19:52Z")

</div>

I know this isn’t a very technically correct solution but you could move those references to somewhere else like the playercontroller or gamemode, you could get references to those quite easily from any object ingame.

---

<div class="post-metadata">

**Author:** ![BaderThanBad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BaderThanBad](https://forums.unrealengine.com/u/BaderThanBad)\
**Post date:** [November 25, 2014, 3:21pm UTC](https://forums.unrealengine.com/t/static-tsubclassof/299836/3 "2014-11-25T15:21:23Z")

</div>

I created my own level info actor and place level specific details there for any object to reference inside levels.

---

<div class="post-metadata">

**Author:** ![BurnGameVen04\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BurnGameVen04\_1](https://forums.unrealengine.com/u/BurnGameVen04_1)\
**Post date:** [November 25, 2014, 4:29pm UTC](https://forums.unrealengine.com/t/static-tsubclassof/299836/4 "2014-11-25T16:29:55Z")

</div>

While that is a potential way of doing it, it wouldn’t work in my case because I can’t pass a reference to procedurally spawning item when it’s another item.

---

<div class="post-metadata">

**Author:** ![BaderThanBad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BaderThanBad](https://forums.unrealengine.com/u/BaderThanBad)\
**Post date:** [November 26, 2014, 1:22pm UTC](https://forums.unrealengine.com/t/static-tsubclassof/299836/5 "2014-11-26T13:22:59Z")

</div>

Hmmm I don’t understand why it wouldn’t work, even in that case. Instead of passing the reference to the item as its spawning why not let the spawning item attempt to get those references.
