ShooterGame in Blueprint

I’m currently trying to recreate the main mechanics of ShooterGame using only Blueprints. Making good progress, however I’m using a single weapon attached to the main character blueprint, and this contains all the shooting logic. Would it be better to create new blueprints for each weapon and somehow call them to be the active weapon in for the character?(If so how could I call the weapons?) This way I could customise each weapon and change meshes etc. Also would anybody be able to explain how the actual playerpawn blueprint is set up in ShooterGame? If someone could give me a little head start into setting up the whole ShooterGame inventory/pawn in blueprint, it would really help a lot! Thanks!

You should create a master weapon in which you do all the basic logic. You should also implement an interface to simulate abstract classes as they don’t exist naively in BP but come in very handy for this.

From then on you create all your weapons with that master class as patent.

In your character you remove the current weapon and spawn the new one on the normal input event.

You call the shoot function which you implemented for the weapon master and which will therefore be available for all weapons without casting to them. Like this you can create as many weapons as you like without any change to your character.

I haven’t looked into the character of the shooter game so I can’t help there. Sorry.

I hope this helps.

Cheers

Thank you for this help! I have a few quick questions:

Would you be able to elaborate on the interface to simulate abstract classes? Would this require some C++? (Not against using it but I would prefer to stay completely in BP if possible).

Would this master weapon just be a standard actor blueprint containing the shooting logic, and then referenced by other blueprints? If so, how would you call it in the “children” blueprints? (via a function?)

Sorry for my idiocy, still learning the ropes, and this would really help my learning! Thanks!

No problem at all.

Interfaces are a blueprint logic. Basically a way to expose functions besides calling them from the actor reference.

There are a few tutorials and is suggest you to read up on it. They are a quite powerful tool.

The master weapon would indeed be a normal actor. However you simply create normal bps but instead of choosing actor you choose your weapon master. You still spawn the children but you can from then onwards cast to both of them. Since you implement the interface in the master but only implement the function in the child you can call it from every bp which has the master as parent but the actual shoot logic is inside of the child.

Many thanks for the help, will get working on this now! Great to have a clear path to look into! Much appreciated!

Hey Erasio, I have made great progress getting the shooting functionality- both the instant hit and projectile weapons work in my blueprint game as they do in the ShooterGame example. However, I created both the instant hit and projectile functions in the main character blueprint, since they reference the camera in the character blueprint (therefore I can only use one type of weapon at a time without changing the fire input to a different funciton). How would I go about setting up my master weapon from here?(or 2 master weapons- one for line trace weapons and one for projectile weapons) In the ShooterGame example, the main character just has the character meshes in it, and no weapon- but how exactly could I spawn , say my line trace weapon blueprint (assuming that is the master for now) into the character blueprint so it is useable?

Sorry if it sounds confusing- I just want to be able to pretty much call the fire function/spawn a weapon blueprint in the correct place of the character blueprint! Thanks!

That’s going a bit deeper into inheritance and why it’s so problematic that we don’t have abstract functions in blueprint.

First of all you can have any number of parents you want. And with that I mean levels not different functions so you’d do a master weapon, then a master projectile weapon and a master trace weapon (if you intend to have multiple).

Since you spawn your weapon in your character you can just provide a reference either to the whole character or just to the camera on spawn to have it working with your current code simply copied over to the weapon bp.

Then as I said you can use an interface to call a function where you just get your currently equipped weapon and call shoot for it.

Regarding the spawning of weapons and how they are used. Well you kinda do it like every other actor with one difference. You attach it to a socket.

Sockets are a way to define a position for a skeletal mesh where you can put stuff (a sword, a pistol, a medi pack… whatever).

Check this out for a bit more information about this:

https://docs.unrealengine.com/latest/INT/Engine/Content/Types/SkeletalMeshes/Sockets/index.html

If this didn’t exactly answer your questions excuse me. I might have not understood everything properly;)

Don’t hesitate to ask again!

Cheers

Thank you for the clear explanations! It makes much more sense now!

I actually tried calling the camera component earlier, but I couldn’t seem to “get” it in the weapon blueprint, after trying multiple casting attempts. Is there an easy way to get it, am I missing something basic?

As for the sockets- ah of course! I was using sockets to place the muzzle flashes on the weapons themselves, but didn’t consider adding a socket on the hand of the character for the gun. If I was to implement a pickup/inventory system, would I then just somehow replace the mesh/weapon blueprint that is currently using the socket with another mesh/blueprint each time the “next weapon” button is hit?

With that said, is there an easy way to simply swap a mesh of a blueprint but keep the same functionality? This would be an ideal way to have the “Master” blueprint function correctly, but be able to assign different meshes to it- so at the start of the game, a player could choose a gun, which in turn would change whatever exposed variables it has (damage/reload time), and the mesh/animations.

Thanks again for the help, much appreciated!

Well you can get the mesh component and set it to something else. There is a direct node for that :wink:

And yes there is an easy way to the camera component. Create a variable in your weapon bp and set it to “editable” and “expose on spawn”. This will provide an additional pin when you spawn that bp where you can simply input your camera component.

Wow, thank you for all the help, everything is cleared up now!

Sorry to bother you once more- I think I finally am nearly there with this problem. I decided to just have every weapon as a master weapon for now, so I can have slightly different functions. But just to get the initial weapon to work, I’m still having trouble casting to it from the Character BP!

Right now, the Character handles movement, and aiming down sights (the camera is attached to the character). The weapon BP then handles firing, reloading, damage, ammo count etc! I can attach the weapon blueprint to a socket on the character mesh just fine, but my problem then is calling the blueprint, so(as a simplified example) that at event begin play, a specific weapon blueprint (which is already attached to the socket), will be able to shoot and function like it did when all the logic was in the character BP itself. I created an interface with the shooting functions, but couldn’t call that in the character BP.

To summarise, I’m just not sure about how to call the BP shooting functions in the character mesh!

Many thanks for your time and help!

Well to call it you need a reference. When you spawn it you should keep that reference in a “temp weapon” or “active weapon” variable and then use it to call the interface function.

It’s pretty much like any other BP. You can’t just call an interface function from everywhere.

Ah perfect! Thanks to your help I have gotten everything working perfectly!