Using an Enum to choose which weapon is spawned

I can make it work, but it’s ugly. I’m hoping that someone can point me in a better direction.

I want to use A (an enum) to determine the input into B:

Like I said, I can make it work:

But this solution is very ugly. Right now, I’ve only made two weapons, but once I have a dozen, things get crowded.

Can anybody suggest a better solution?


This is the way.

A leaner solution would be to create a Map property that holds the enums and the projectile classes. You would use the Find node on the map to get the projectile class and plug that into the Spawn node.

1 Like

u can use a select node

1 Like

Ok, thank you. That looks a lot better.

why not just pass the TSubclass directly which holds all the weapons of the type you wanna spawn. it will be like a variable that you can reassign if you want to spawn a different weapon.

I don’t know what that means, but thanks for trying.

ops my bad, I thought this was CPP section.
What I was trying to say is you can just have a variable that holds what type of Actor you want to spawn.
just drag off the pin from SpawnActor called class and type promote to a variable.
now all you need to do is reassign that variable if you want a different weapon to spawn and re-run that spawn function again.

How did you get your select node to show the dropdown for the weapons? What is your “overlay state” variable?

I got the mapping thing to work. Thanks for the suggestion. It really cleaned things up.

The “proper” way is to make a weapon class as a master class to derive weapons from that just handles what it spawns.

A simple interface call would do…

Then, when you create weapons and inherit from your weapon class.
All your standardized calls will be present, plus you can override for customization purposes…

This is kind of a basic OOP concept…

I don’t understand anything you just said.

Then you need to study.

I’m sure there’s supposed to be a comma in there somewhere, just not sure where. It like the sentence, “I love cooking my family and my pets.” Without the commas, it has a completely different meaning than , “I love cooking, my family, and my pets.”

That makes no sense. An interface call to what?

Did you even read any of the previous posts?

But hey, thanks for the arrogant attitude and the non-help that was completely non-helpful.

Go study some etiquette, and maybe throw in some study of how to properly punctuate a sentence.

Also, I don’t really need your attitude, so if you have no intention of being helpful, please avoid my questions in the future.

I do avoid your questions. As they are almoat always about as silly as it gets.
It’s clear now that this is simply because you have an abysmal lack of knowledge.

Fix it.
Instead of asking near pointless questions about specific situations like you do - which obviously has gotten you nowhere for the past 6 months - go into the Learn tab, and take the courses related to game development.

They won’t teach you the basic conceps of OOP, which you obviously lack, but at least they’ll give you some additional tools to allow you to answer your own qquestions.
Then again it doesn’t seem like you are actually willing to learn at all, since you basically beg for cookie cutter solutions in most posts.

Not necessarily. It isn’t a run on, though I’ll admit it’s not the best sentence structure.
Let’s fix it like this:
The “proper” way is to make a weapon class as a master class to derive weapons from.

Do you know what an interface call is? No? Study it.

“Interface call To what?”
To the weapons class, obviously. Or are we talking about cabbages here?

Of course I did. Why else would I chime in to tell you they are pointlessly BAD ideas if I hadn’t red them?

@Lord_Volkner @MostHost_LA May I suggest both of you calm down a little. Neither of you is acting as a paragon of good communication right now.

I don’t always appreciate MostHost_LA’s posting style either, but what they wrote above about the master class thing is pretty clear and easy to understand if you’re familiar with basic modern programming concepts. If you’re having a hard time to follow, that means there is some gap in your knowledge that you should at least be aware of.

On that point, for what it’s worth, it is true that there are very likely better ways to implement a weapon and item system. I didn’t mention any of that because the original question was not “Am I doing this right?” but “How do I get it to work the way I want to?”.

Finally, to settle the most important part of the argument, the sentence was in fact grammatically correct. English comma rules are kinda sucky in my opinion, but that’s really starting to get off topic.

1 Like

Everyone starts with an abysmal lack of knowledge. We come here to get help learning.

NEWS FLASH: if we knew what they were doing, we wouldn’t be here asking questions!

But, thanks for trying to help. I’m sure I’ll come back here in the future and maybe then it will make more sense to me.

… and I should have answered better. I said

but that isn’t true. I understand the weapon master class, I have one. And I understand what an interface is, I just don’t know how to use the interface to set the weapon type on a spawned pawn, which is what I was trying to figure out.

So, thanks. I’m sorry I don’t understand that. Forgive my irritation. Peace.

Yeah, you’re probably right.

I’m sure it makes perfect sense if you know what it means, but it’s less than clear if you don’t. I’m sure that he knows what he’s talking about, but he didn’t bother to explain anything, so it wasn’t very helpful. No problem, he has no obligation to do so, but the attitude and insults, I can do without.

Anyway, the problem is solved now, thanks to you. That worked very well. Thanks again.

If you’re referring to the Select node, that is not a great solution, imho. It will work OK-ish, though.

The way the Select node evaluates things is convoluted. To my understanding, all those classes would be loaded for the sake of evaluation (someone corrects me if I’m wrong!) even though they are not needed. This is the place where you’d use a soft class reference instead.

A map was mentioned above, this could work:

This way you end up with a variable that you can modify and save. But without seeing the big picture, It’s hard to tell whether this is of any use here.


The mapping version is the version I used, not the Select node. Pretty much exactly what you show there except that I have a reference to the enum going to the lower left pin of the Find node. It gets the job done.

I have no understanding of the soft class reference, but I’m at work with nothing to do, so I’m going to watch the video you’ve linked.

As always, I appreciate your input and those links to learning resources.


1 Like

If that were true half if not 70% of the forum posts wouldn’t be conglomerates of begging for specific situations.

Truly, I wish that were the case.
Unfortunatley most post wind down to the equivalent of a 5yo asking why the sky is blue.
You can explain the science… but being 5, they’ll probably just ask “what is reflection”.

Once you take out the 1% of posts from people acrually attempting to learn something, the rest is people downright begging the community to do their work for them…

That may be the case, but have you maybe tried to Google for an answer given the few words and parameters introduced during the conversation?

Your answer was literally “I don’t understand”.
That’s not really OK.
There’s no reason for you (or anyone) not to understand if you put in the time to look it up…

Nor should there be any reason for us to give you precise instructions tbh.

It’s up to you (and everyone else asking for help just the same) to acrually put in some effort to try and learn.

Had you said
“I tried looking this up, but couldn’t find anything about it” things would have gone differently tone wise…

I wasn’t aware that telling people to study was an insult. How egregious of me… I have been insulting people a lot through out my life and didn’t know it :stuck_out_tongue:

If you feel insulted by how I phrased things, you should probably go do something else for a bit.

I’m sure it’s just a byproduct of the engine. It makes everyone irritable…

BY the code snippet you showed, you aren’t trying to spawn a different weapon to equip.
You are trying to spawn a different Projectile.

The projectile spawning must be handled by the individual weapon blueprint.
For loads of reasons. Chief among them is different settings on them based on the weapon itself.

To just “equip” a different weapon, there’s different solutions as well. The select isn’t the best.
Gameplay tags with weapon names would already outperform this…

As with every other post (of yours or of others).
WE can’t read your mind to know what it is you are attempting to do.
NOR, do we know what your project parameters are unless you tell us.

For instance. We don’t know if your inventory slot and key assignment is supposed to be fixed (one weapon always on that slot) or variable (user selects what weapon goes to what slot).
For that matter, we don’t really even know that you have an inventory or a slot.

The select can be helpful, maybe, but its probably completely useless if you set things up correctly.

As I said. Take to the Learn tab. There’s a lot of different things/ways you can go about this.
The game stuff in the learn tab though boring covers most of the basics for everything.
Soft classes too.