Could I please get a simple explanation of TSubclassOf

TSubclassOf<AWeapon> is a reference to a specific class, as long as that class’ inheritance hierarchy includes AWeapon. In Blueprint, you specify which particular class it’s referring to (either BP_1 or BP_2), but the drop down knows it has to be some sort of AWeapon, so it lists all the AWeapons to make the choice faster/easier for you. But from the C++ side, TSubclassOf<AWeapon> doesn’t refer to ALL the subclasses of AWeapon, only to the specific one chosen in the Blueprint dropdown.

If you want to access values of that blueprint, the values should probably exist on the parent. ie: EnemyKills, MaxAmmo, etc are variables defined in AWeapon. Because the child classes (BP_1, BP_2) inherit from AWeapon, they can set those variables, and because C++ knows it’s some sort of child of AWeapon, it can also access those variables.

If you’d rather have variables that only exist in Blueprint (…for whatever reason), then you probably should use functions to get that data, and the functions should be defined in AWeapon, and (re)defined in each individual Blueprint to return the needed values.

2 Likes