Type name is not allowed error is thrown out when StaticClass method is not existed . What type the class that PawnName is referred to is ? I know StaticClass is used to return a UClass on things that are not instances/UObjects . I know UClass contains reflection data , but why can’t that be compiled when game is running but I need to pass the reflective UClass into slot to set ‘defaultpawn’ as a reflective UClass ?
Maybe I misunderstanded it . From my view ,I guess StaticClass is a method of UClass so what’s the point to get UClass from a UClass ?
StaticClass is a static method of the class (APawn, etc) not of UClass. There no C++ language support that would allow for something like DefaultPawnClass = APawn
since typenames aren’t r-values (an r-value is just a thing that can exist on the right side of an equals).
So: DefaultPawnClass = APawn::StaticClass( )
is calling a static method of APawn, which returns a UClass which, as you correctly identified, contains the reflection information for the APawn type.
How can it know who is typename and who is not ? I remember classes are defined as UClass . I guessed so since they’re UClass by definition but it seems not , what’s the little difference ?
I’m not really sure how to answer your question, but I’ll try my best.
Typenames are any of the types that you can use to declare variables. Things like int
or float
are built in, but anything that’s been declared using the class
, struct
or enum
keywords also define a new type. There are more but we’ll ignore those for this discussion.
So since you can do APawn *pawn
to declare a variable, APawn
is a typename. Typenames only exist for the compiler which is why you can’t assign it to anything.
It seems like you might want to focus on learning vanilla C++ before diving into writing code in Unreal.