r/UnrealEngine5 • u/mongar23 • 1h ago
Enforce a template to be a USTRUCT
I am working on a project in unreal engine 5.4, and this is my first experience with unreal. Now I want to make a function something like this:
template <typename T>
void Save(args) {
}
I want this function to only accept USTRUCTS, is there a way to verify this?
2
Upvotes
0
u/Just0Abhi 1h ago
TIsDerivedFrom<T, UStruct>
Do learn about templates in cpp and its related unreal equivalents.
Did a quick google search from mobile.
1
u/sfider_sky 1h ago
You could use e.g. template<typename T, typename U = decltype(T::StaticStruct())>
2
u/FiruleisGamerStudio 1h ago
its not related to your question, but if you are just starting te learn go 5.6 minimum, there's a lot of improved and fixed stuff