TSubclassOf ProjectileClass is NULL (Unable to create custom projectile)

I started with the 3D First Person Shooter Template C++ project. I took the original projectile that comes with the template and made it into a parent class ASpellWorldProjectile. I have a class ARandomProjectile that is a child of ABaseProjectile.

The original code that was there was this:

TSubclassOf<class ABaseProjectile> ProjectileClass;

And that was working because ProjectileClass was not null. But when I try to change the code to this:

TSubclassOf<class ARandomProjectile> ProjectileClass

ProjectileClass is now null. I tried to bypass this by instead using ARandomProjectile::StaticClass() but this causes the projectile to not be rendered.

Here is a link to the ARandomProjectile code

And here is a link to the ASpellWorldProjectile code

Can you possibly post both the .h. and .cpp files for whichever class is containing your 2nd line there? On pastebin.com or https://gist.github.com/

I figured out what my issue is and it stems from me being a C++ programmer and being new to Unreal Engine 4.

In my BaseProjectile (ASpellWorldProjectile), I have instance variables/member variables for

  • Projectile movement component
  • Collision component

But nothing for the SkeletalMesh which is the visual representation of our BaseProjectile. So when I inherit from BaseProjectile I should get all the data associated with the parent but where does the SkeletalMesh come into play? Why is my projectile working fine but it is invisible/not being rendered?

The answer is because Unreal Engine 4 manages assets for you meaning you don’t make a SkeletalMesh instance variable but instead you create a blueprint that has your C++ code and attaches the SkeletalMesh to the blueprint. Essentially, the blueprint ties together your visual representation and your C++ class.

Below are the steps I did to tie my C++ code to the blueprint.

First we need to make the blueprint so double click the blueprints folder to navigate to it.

http://i.imgur.com/tqEFrPO.png?1

Right click in the folder and create a new blueprint, Have this blueprint inherit from your child class (In my case ARandomProjectile).

https://i.imgur.com/mmKfjpR.png

Open up the blueprint we just made and click the button “Add Component” to add our SkeletalMesh to the blueprint. (You might need to zoom out to see the yellow sphere mesh).

https://i.imgur.com/Itxo6dL.png

Modify the data of the new SkeletalMesh to use the same mesh from the Base Projectile. Make sure to compile the blueprint when done.

http://i.imgur.com/rGNEQGJ.png

Now we need to tell the player to use the ARandomProjectileBlueprint we just made because if we just tell the character to use ARandomProjectile, it will be invisible.

http://i.imgur.com/Gmrm4op.png

Last but not least make sure that in the blueprint for the character, its using our new blueprint. Make sure to save all and click compile for this blueprint as well.

http://i.imgur.com/UmXZd2R.png

I hope this was helpful, This fixed the issue for me perfectly.