# Templated USTRUCT?

**URL:** <https://forums.unrealengine.com/t/templated-ustruct/354096>\
**Category:** Editor Scripting\
**Tags:** Struct, ustruct, Class, unreal-engine, template, CPP, question\
**Created:** [April 13, 2016, 11:19pm UTC](https://forums.unrealengine.com/t/templated-ustruct/354096 "2016-04-13T23:19:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelWion](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MichaelWion](https://forums.unrealengine.com/u/MichaelWion)\
**Post date:** [April 13, 2016, 11:19pm UTC](https://forums.unrealengine.com/t/templated-ustruct/354096/1 "2016-04-13T23:19:25Z")

</div>

Is there any way to use templates/generics on USTRUCT objects (or even UCLASS)?

For example, something like the following:

```
USTRUCT(Blueprintable, Category = "Scripting|Remote Character|Attributes")
template<typename Type>
struct FRemoteCharacterSubAttribute
{
	GENERATED_USTRUCT_BODY();
public:
	FRemoteCharacterSubAttribute() {
		Name = FString(L"Unassigned");
		BaseCost = 0.0f;
	}

	UPROPERTY(BlueprintReadWrite, Category = "Scripting|Remote Character|Attributes")
	FString Name;
	UPROPERTY(BlueprintReadWrite, Category = "Scripting|Remote Character|Attributes")
	float BaseCost;
	UPROPERTY(BlueprintReadWrite, Category = "Scripting|Remote Character|Attributes")
	Type MinValue;
	UPROPERTY(BlueprintReadWrite, Category = "Scripting|Remote Character|Attributes")
	Type Value;
	UPROPERTY(BlueprintReadWrite, Category = "Scripting|Remote Character|Attributes")
	Type MaxValue;
};

```

… And then you would use it like:

```
USTRUCT(Blueprintable, Category = "Scripting|Remote Character|Attributes")
struct FRemoteCharacterAttributes
{
	GENERATED_USTRUCT_BODY();
public:
	FRemoteCharacterAttributes() {
		fMovement.Name = FString("Movement");
		fMovement.BaseCost = 10.0f;
		fMovement.MinValue = 50.0f;
		fMovement.MaxValue = 500.0f;
		fMovement.Value = fMovement.MinValue;
	}

	UPROPERTY(BlueprintReadWrite, Category = "Scripting|Remote Character|Attributes")
	FRemoteCharacterSubAttribute<float> fMovement;
};

```

Any way to make this happen?

---

<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:** [April 14, 2016, 9:33am UTC](https://forums.unrealengine.com/t/templated-ustruct/354096/2 "2016-04-14T09:33:57Z")

</div>

Hi Michael,

Template USTRUCTs, UCLASSES, UFUNCTIONs. etc. are not supported in any form, and are unlikely to be.

Steve

---

<div class="post-metadata">

**Author:** ![michal.buras](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@michal.buras](https://forums.unrealengine.com/u/michal.buras)\
**Post date:** [July 18, 2018, 10:45pm UTC](https://forums.unrealengine.com/t/templated-ustruct/354096/3 "2018-07-18T22:45:45Z")

</div>

Is there any change on the subject of templates ?  
Or any way to generate ustructs ?

---

<div class="post-metadata">

**Author:** ![FedericoCodeLane](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FedericoCodeLane](https://forums.unrealengine.com/u/FedericoCodeLane)\
**Post date:** [May 24, 2022, 8:37am UTC](https://forums.unrealengine.com/t/templated-ustruct/354096/4 "2022-05-24T08:37:00Z")

</div>

Any news on this front?

---

<div class="post-metadata">

**Author:** ![Repin\_Design](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/repin_design/32/598391_2.png) [@Repin\_Design](https://forums.unrealengine.com/u/Repin_Design)\
**Post date:** [November 9, 2022, 6:41pm UTC](https://forums.unrealengine.com/t/templated-ustruct/354096/5 "2022-11-09T18:41:48Z")

</div>

```auto
template<typename T>
struct FTemplateStruct: public TSharedFromThis<FTemplateStruct> {

	TSubclassOf<T> Class;

	T* Object;

};

```

this is also not working, then the question, how to make sucha struct not to be cleared by garbage collector?

---

<div class="post-metadata">

**Author:** ![0xd0d9e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@0xd0d9e](https://forums.unrealengine.com/u/0xd0d9e)\
**Post date:** [July 2, 2024, 6:28pm UTC](https://forums.unrealengine.com/t/templated-ustruct/354096/6 "2024-07-02T18:28:36Z")

</div>

There is an error in your code from the C++ point of view.  
You have incorrectly specified the type in TSharedFromThis.

This should work correctly

```auto
template<typename T>
struct FTemplateStruct: public TSharedFromThis<FTemplateStruct<T>> {

	TSubclassOf<T> Class;

	T* Object;
};

```

The topic starter has a different problem that still hasn’t been solved. Apparently, UBT does not support templates, so it cannot generate code related to reflection support for them.

P.S. I apologise for the necro post.

---

<div class="post-metadata">

**Author:** ![Yazhuo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/yazhuo/32/894946_2.png) [@Yazhuo](https://forums.unrealengine.com/u/Yazhuo)\
**Post date:** [September 1, 2024, 8:19am UTC](https://forums.unrealengine.com/t/templated-ustruct/354096/7 "2024-09-01T08:19:04Z")

</div>

So，if we can rigister reflection after creating template struct?  
Reading sorce code “Range.h”,and you will find that all of Range are created by template,but they can use Property System. I dont know how they do it,and where they rigister reflection.  
Is any idea?

---

<div class="post-metadata">

**Author:** ![Repin\_Design](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/repin_design/32/598391_2.png) [@Repin\_Design](https://forums.unrealengine.com/u/Repin_Design)\
**Post date:** [January 6, 2025, 6:43am UTC](https://forums.unrealengine.com/t/templated-ustruct/354096/8 "2025-01-06T06:43:22Z")

</div>

> [@Yazhuo](#):
>
> Range.h

any news?

---

<div class="post-metadata">

**Author:** ![Yazhuo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/yazhuo/32/894946_2.png) [@Yazhuo](https://forums.unrealengine.com/u/Yazhuo)\
**Post date:** [January 7, 2025, 2:01am UTC](https://forums.unrealengine.com/t/templated-ustruct/354096/9 "2025-01-07T02:01:08Z")

</div>

No idea.  
Someone tell me that you can write reflection infomation in other place. but not the detail.  
I want to giveup,cause I just need the templated stuct for int and float. I create them in traditional method.  
But it still is a interesting study.
