Could I please get a simple explanation of TSubclassOf

To elaborate a bit more to TheJamsh’s reply:

TSubclassOf is basically a pointer to a UClass object, which just describes an object type. You can grab the CDO from a TSubclassOf like so:



if (*BulletBP) // This just checks if the TSubclassOf is valid and not pointing to a nullptr or anything.
{
  ABullet* MyBullet = BulletBP->GetDefaultObject();
}


Each time you compile a Blueprint, you are making a unique class. So your properties and such should be there. Just realize changing the CDO changes all instances of that class. If you wanted to grab a version you could alter at runtime, you’d want to do something like:



ABullet* MyModifiableBullet = NewObject<ABullet>(GetTransientPackage() /*or owner, or whatever */, *BulletBP);


2 Likes