Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 https://gist.github.com/anonymous/5d42c9e3418204176d0c

And here is a link to the ASpellWorldProjectile code https://gist.github.com/anonymous/0e54c8ab422b21d25591

Product Version: Not Selected
more ▼

asked Mar 15 '15 at 06:31 PM in C++ Programming

avatar image

151 27 21 30

avatar image HateDread Mar 16 '15 at 03:58 AM

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/

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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. Screenshot to make initial blueprint.

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

Screenshot to make initial blueprint and tie it to child class.

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). Add SkeletalMesh component

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

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. Set the player to use the blueprint we just created

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.

Make sure the character blueprint is using our new projectile blueprint as the default.

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

more ▼

answered Mar 17 '15 at 06:55 PM

avatar image

151 27 21 30

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question