On the cusp of understanding this - Weapon Base system

Hi all, please bear with me as although my understanding of all of this has gotten significantly better over the past few months, I still have plenty of n00b questions in me.

I am basically trying to create and implement a weapon system, which i know is a topic brought up many times, but I have some questions more specific than I can find. Let me try to explain my current set up.

I have a weapon_base class, with no mesh, and two custom events atm, - fire and reload. I currently have two weapon blueprints of their own - a bp_rifle and a bp_pistol that both inherit from the base weapon class. In my character blueprint I have a variable that stores the current equipped weapon, as well as an enum with all weapon types inside. (This will be used for setting equipped weapon variable - I think)

Here are the things I am a bit confused about:
1 - For the “Fire” and “Reload” events in the weapon_base class - do I leave their definitions blank (ie dont hook executable up to anything) and only assign them functionality within the specific gun (child) blueprints?
2 - For spawning the weapons, do I spawn the actual Base Weapon Class, and switch current gun actor from in there, or do I just spawn the specific gun blueprints?
3 - I also have a projectile_base class - but I am entirely unsure, if/how to use it. Each gun will have its own bullet mesh, as well as projectile physics so I’m kind of lost there.

Overall am I even heading in the right direction? Any help would be greatly appreciated

  1. For your first question, it depends. Reload/Fire operate in a similar fashion regardless of the gun type? If so then you can implement the gun base functions and each extended version will use that code when reload/fire events are triggered. However if each gun type needs its own reload/fire functionality then you’ll want to override it in their blueprints.

  2. You need to spawn the gun’s specific blueprint. That way it calls that blueprint’s overridden interface.

  3. I would recommend you create a similar setup as you did for the guns. Base bullet class with an extended version for each gun type that needs different functionality.

Of course. If you have any further questions or need more details feel free to ask.

Is this a different blueprint that has an actor object reference?

Take a look at this document:

https://docs.unrealengine.com/en-us/Gameplay/HowTo/SpawnAndDestroyActors/Blueprints

If you look at step 3, you notice they are setting the actor class type. If you have the variable mentioned in your previous post you can pass it along here to tell the node which gun to spawn.

Sounds good. If it doesn’t work then attach a screenshot of the blueprint in your message so I can see what is happening.

Thank you so much for the quick and efficient answer.

One more question if you know the answer - So at the moment I am capable of setting an actor object reference variable to any of the gun bp’s that are derived from the base - but how can I spawn using that variable?
Edit: The actor object reference being my “Equipped Weapon” variable

The Actor Object Reference is contained within my character blueprint - more specifically within a function that does a switch on enum and sets it based on the active value. I did try yesterday to use a variable for the class input of the SpawnActorFromClass - but the return value kept giving me none. However the way in which my entire system was set up was different, so I will give it a go and let you know what happens

Yea its not working. It seems whenever I try to use a variable for class on that spawn node it just returns none. Probably just an amateur mistake, but give me a minute I will upload some screen shots

Ok, So the first picture here is of the function that sets the “equippedweapon” variable (inside character blueprint):

From within the event graph of my character, I attempt to spawn the equipped weapon:

This compiles, and runs. In game, my animations work (just a pose by enum) but the weapon doesnt spawn:

Upon leaving the preview I am greeted with the following error:

And I can see that the return value of the spawnactorfrom class is none.

For the record, if you look in my list of variables there - you see the one called “spawn class”. I tried setting that manually and plugging it in - still doesnt work

Is active value set to none? I’m guessing that the set weapon call isn’t setting up the equipped weapon variable because active value is set to none.

Try putting a breakpoint on the switch node and checking the value to see what’s happening.

You mean active value going into enum? By default its none but if you look there in the even graph I have the value changing before the spawnactor. To be honest, I’m not entirely sure what you mean by breakpoint, could you clarify?

If the active value is set to none by defualt, then the switch is going to set IsArmed to false and equipped weapon is never going to be set. Which is why the error is saying that the spawn actor is receiving none.

Right click the switch node and you’ll see an option to add a break point. Next time you run the game it’ll stop here when the function is called and you can check the values of active value.

Take a look at this link:

Breakpoint debugging is an invaluable tool that allows you to see the state of your game at any point in code. You can step through your functions to see what is happening from one node to another.

I’d be happy to take a look at your project to see if I can find the problem if you want to share your project.

Hmmm The breakpoint thing is entirely new to me, will have to look into that. I set the active value to smg45 by default - same result except my animation plays automatically but still no weapon

I’m not sure if I am able to share it, as there are some purchased assets used in it and im not really sure of the rules regarding such. Sorry for the delayed response, I’m just seeing your responses now, will have a look at the link

the breakpoints are extremely useful, thank you for that

No problem. Its the most ideal why to find out what went wrong in your code. See if it helps you get to the root of the problem you’re having.

If the problem still persists, let me know what you’ve found out so far and we’ll see how else we can isolate it.