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:
And that was working because ProjectileClass was not null. But when I try to change the code to this:
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 https://gist.github.com/anonymous/5d42c9e3418204176d0c
And here is a link to the ASpellWorldProjectile code https://gist.github.com/anonymous/0e54c8ab422b21d25591
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
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.
Right click in the folder and create a new blueprint, Have this blueprint inherit from your child class (In my case ARandomProjectile).
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).
Modify the data of the new SkeletalMesh to use the same mesh from the Base Projectile. Make sure to compile the blueprint when done.
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.
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.
I hope this was helpful, This fixed the issue for me perfectly.
Follow this question
Once you sign in you will be able to subscribe for any updates here