Optimizing actor classes for naval turrets (turrets, cannons, projectiles..)

Hi everyone,

I’m trying to optimize a workflow for creating multiple naval-style turrets (3rd person top-down game, with the turrets looking at the cursor on a 2D plane, Yaw rotation).

Currently, I have something working using the following method :

  • The ship hull class has sockets which are the hardpoints where the turrets can be spawned.
  • The turret has 1 or more sockets for attaching cannon in BeginPlay.
  • The gun class handles the reload timer and spawn the projectile from its barrel socket.

This works. However, with this method, I need to create classes for both turrets and guns.

Ideally, I’d like to have a master “Turret” class, which can be derived into final turrets (simple gun, dual gun, triple guns, etc…) where I can select the mesh for the turret & guns, as well as Niagara shooting effects, and basically have all the code here. This way, I can skip making all the gun actors (they would just be static mesh with a socket at the end for bullet spawn).

However, for each individual gun, I need to keep track of the reload time and ammo type, and I can’t really wrap my head around that. Currently it’s pretty easy because they are all separated actors, with individual variables, tick and fire functions taking care of the reload timer (which is just a bool + a Delay function)

So my questions are : is it even a good idea to do that ? And if so, is it doable ? How can I keep track of all the gun states and timers separately inside the turret if they are not individual actors ?

side note : I find it extremely frustrating to be forced to modify my base meshes to add sockets where things can dynamically spawn. I liked Unity’s ability to make “null object” inside prefabs (class viewport in UE) MUCH MORE. This was way easier to use and allowed you to keep your base mesh unchanged.

1 Like

You can definitely make an empty gun turret class, and inherit from that.

Each common variable ( #turrets, reload time, shell type, max ammo etc ) can be defined in the parent class, and then set in the inherited class.

As far as the null goes, you can just put a bare mesh in a blueprint, and use scene components the specify where ( and in what transform ) you want to attach other blueprints or meshes to the blueprint. A scene is empty.

1 Like

Thanks for your reply, I think I’m onto something.

What I’m testing right now, which I think is what you were hinting to, is to have childActors in my turret, which are all instances of the simple “Gun” class without mesh.

Using a public Static Mesh variable, I’m able to set the gun mesh to be used directly from the Turret BP viewport.

For the gun to actually be visible in the Turret BP viewport, I need to set the static Mesh in the Gun Construction Script, otherwise it doesn’t work (I could still set it in the Turret initialization, but it’s harder to see what you are doing when the guns are not showing).

“Artillery Mesh” is the empty static mesh placeholder, “Static Mesh” is the public variable that I change directly in the Turret viewport when I click on the Gun ChildActor.

So far so good, I still need to figure out exactly how to handle the firing effect now, as previously it was placed in the Gun class, but as now only have a placeholder mesh that’s gonna change for each instance, I might need to either use the Cannon Mesh bone, or put it in the Turret class.

1 Like

Good you made some progress :slight_smile:

Because the guns are child actors, you can configure them directly from the parent blueprint, in the details.

You can also use an interface to send the fire and reload instructions, rather than casting.

This is just one of many ways of doing this. It’s hard to know if the solution will scale well for you yet. Best thing is to try going a bit further.