Battery Collector #5 – Extending the Pickup Class

I am continuing the Battery Collector in C++ tutorial from Unreal Engine. This is the 5th video.

Extending the Pickup Class

In this part, we will create a Battery Pickup based on the Base Pickup we created previously. To do that, we add a new class in the Unreal Engine Editor and click on “Show all classes” to be able to search our Pickup class:

BatteryCollectorNewBatteryPickupClass

I name this new class “BatteryClass“.

In the header file, I declare the constructor:

public:
 // Sets default values for this actor's properties
 ABatteryPickup();

And in the source file BatteryPickup.cpp, I set the physics true for the mesh:

ABatteryPickup::ABatteryPickup()
{
 GetMesh()->SetSimulatePhysics(true);
}

Back to Unreal Engine editor, I create a blueprint based on this class. I name it “Battery_BP” and place it in the Blueprints folder.

In the blueprint editor, I set the mesh with the SM_Battery_Medium:

BatteryCollectorBlueprintMesh

Then I compile and put a battery in the world. When I hit play, the battery falls through the floor. The reason is that the mesh doesn’t have any collision. To fix that, double click on the mesh to get the Static Mesh editor. In the top menu, I open the Collision menu and I select “Add 10DOP-Z Simplified Collision” which add a collision cylinder on the Z axis:

BatteryCollectorBatteryMeshCollision

However, it is better to add a “18DOP-Z Simplified Collision” which is more precise. This is done by removing before the collision in the collision menu. I save the mesh and when I hit play, the battery falls on the floor.

BatteryCollectorBatteryInLevel

Next Steps

In the next step, we will create a spawn volume.

About

Gamer

Tagged with:

Leave a Reply