Smart Projectile Integration Tutorial
Integrating Smart Projectile with an existing project.
In this example we'll be using the Flying Template so we can add some turrets to the UFO.
Smart Projectile Integration Tutorial
Integrating Smart Projectile with an existing project.
In this example we'll be using the Flying Template so we can add some turrets to the UFO.
Table of Contents
Create a new project.
Create a new Smart Projectile Project.
Open the Smart Projectile project and migrate the SmartProjectile folder into the flying template project that you created in Step 1 (in your case, it would be migrating it into your own project). You can find more detailed information about asset migration here
Once the migration is complete, open your project.
Before we proceed, we need to make sure we have the correct collision and physics settings. Smart Projectile checks for surface and collision types on hit so this is an important step to ensure proper projectile behaviour.
Go to Project Settings > Collision.
First thing we’ll add is the collision settings.
There are one of two ways you can do this:
Import the collision settings – Warning: this will overwrite your current settings so if you have any custom collisions you should skip this step and add the collisions manually instead!
Manual setup.
If you wish to proceed using the import method, you can download the Collision, Physics and Input settings from here
Click Import.
Choose the Collision_settings_Smart_Projectile file.
Done! Your collision settings should now be updated.
For a manuel setup here some screenshots from the original collision settings as well.
If you want to use the collision marker you have to add a new trace channel as well.
Smart Projectile use collision profile to give you the abilitly to filter out any object or trace channel.
Note: Any other profiles are on the default settings in the ini file from Smart Projectile.
Next step is to set up the physics settings. Repeat the same process as the collision import but select the Physics_settings_Smart_Projectile file instead.
After you've imported the new physics settings you should see the same surface types like at the picturce down below.
Warning: This will overwrite any surfaces that you have already created – you can add surfaces manually if you prefer (see image below).
After you've imported the new physics settings you should see the surface types below.
In this example, we’re importing the Input settings as well just for test purposes but this step is not required (you should have your own input settings). Importing input settings can be done the same way as the collision and physics were done. Simply go to Inputs > Import and select the Input_settings_SmartProjectile file instead.
You will see an example of how easily can create any type of character with a customizable weapon system regardless of how far your camera is from the character. Smart Projectile will always calculate the right position between the weapon muzzle and the crosshair.
Open FlyingPawn blueprint.
Step 1) add the SP_BP_SmartProjectile_TPP component to the blueprint.
Step 2) Then add to two cylinders to the Root component, rotate and scale it like the picture below. Add a new Collision Sphere to each cylinder and scale it down a bit. The Collision sphere is the muzzle of our turret.
Step 3) Add the logic to the FlyingPawn blueprint. To do this switch over to the event graph and create the following logic.
End Result.
Now we’ll talk about weapon classes which is just an actor without camera that is attached to the character which is the Owner of this weapon class.
I don't want to explain here how you should make a replicated weapon because the project includes this already. I will explain what you really need to communicate between your character and your weapon blueprint which holds the Smart Projectile component.
Firstly, we need a correct setting for the owner in our weapon class before we shoot our weapon.
Note: If the owner is changing at run time please make sure that you clear the Actors to Ignore array and add the new owner to the array in the component because that can cause issues for the calculation and for the correct hit registration on the server.
Note: In this example the Pawn variable is a public variable which is exposed on spawn so if we spawn the weapon from the character class, we set the reference to the character blueprint.
In your project you can handle this in whatever way suits you best. The important part is that you have access to your character blueprint somehow.
You can see at the picture how I handle the weapon spawning in the Base Character class. All three pin's where we connected the self variable which is in this case the pawn it self are important for a correct functionality.
Note:
The Inventory is just an array on the character for testing - thi is not a "real" inventory system.
What is the Instigator?
The APawn that is responsible for damage done by the spawned Actor.
Next we need a reference to the player camera. If you have a direct reference to your character you could use it but I'll demonstrate how to do it with an interface - this is how it's implemented in the project already.
Implement the BPI Character interface in your character blueprint.
After you've added the new interface, you’ll have some new functions exposed to the player character.
Double click on the Get Player Camera and add the camera component to the function like this.
After you've done with this step the Get Player Camera function will be valid in the weapon blueprint. Then promote it to a variable and now you have a reference to the owner's camera.
How to fire the weapon from the character blueprint and receive it in the weapon blueprint? There are several options for this I'll show you one that's implemented in the project.
This is the Event on the character which will be called from the Input Action with some other logic. We make an interface call on the primary weapon ( the primary weapon is the equipped weapon in the hand from the character) and that's it.
We implement the BPI Weapon interface in our weapon blueprint that we can receive the interface call from the character.
This is the fire logic in the weapon blueprint. The set damage node is not required for the functionality but you can use it if you have your own variable in your weapon blueprint.
Note: If you use Smart Projectile with a third person character your weapon must have a muzzle collision helper and should looks like this. This is a collision sphere like in the example with the UFO turrets.
In the Project itself you can find example for first person perspective and also for a changeable perspective between first- and third-person perspective. You can also find for all three options with a child component which makes the integration easier for you.
Enjoy! 😃