Help finding out how to switch between weapon classes


I have created a player input component (bindaction), for switching weapons, this is also in the project settings as seen here
image

along side this i have created 2 seperate classes for both weapons, as seen here, at the end of the code,the active gun is what shoots, according to the CPP File
image

image

i want to know what i should add in the end of my action mapping, to switch my weapon class, could someone give me a piece of advice? or help me?

Is that all you have so far on this? You don’t have anything to store the guns? Just the gun classes?

this is all i have so far on this, i don’t know how to make a weapon array, i’ve thought about using a float variable to assign a number to the weapons in question, 1 for the rifle, and 2 for the launcher, but im not entirely sure how to write this in code.

What trouble are you having with that? You’ve created array’s before in Crypt Raider and Toon Tanks. You’re spawning AGun's so you would want an array of AGun

Why a float? Do you expect to have 3.14 guns?

I was going for a walk earlier and came to the same conclusion, to use a TArray instead

image

Does that give you compilation errors?

nope, not anymore, however i have begun running into entirely different problems, my game crashes the moment an enemy lays eyes on me, and starts to fire at me, i can shoot enemies just fine, nothing happens then.

i have made multiple changes to multiple files, do you mind if i share the files in question? switching weapons in itself works, at least, switching between the two classes

What does the crash report say?

And what’s line 27 of Gun.cpp?

if (MuzzleFlash)

I suspect that you’re calling PullTrigger on a null pointer. Is the enemy spawning a gun?

image

i just checked, no he doesn’t, So it is pointing to a nullptr

im not entirely sure how to equip him with a weapon class, could you help me with setting that up? there is another issue i also seem to be having at the moment…

Same way you did it with the player.

i can’t believe i forgot to re enter the weapon classes for the shootercharacter, oh well.

i’m running into just ONE more issue, when i switch weapons, the model disappears from my characters hands, after switching twice, but the functionality still works perfectly as intended

I’m going to attempt to fix this myself…

oh goodness gracious, i have resolved the issue myself, i now feel, like a certified smart cookie

1 Like

Privacy & Terms