Experimenting with a first person shooter, but I have a few problems.

The first block of code is how I project a laser beam from the gun barrel to the target, which is a collision sphere on the end of a spring arm, but this block of code here causes lag over time and a ton of errors.

The second is my system for switching between weapons (The third option is unfinished, ignore it), I originally wanted to shift through weapons via a scroll wheel but for some reason, the scroll axis kept resetting after I finished scrolling so it would set the model index right back to option 0.

The third is the block of code that allows my weapons to fire, first row is the laser and second row is a normal ballistic gun. I’ve figured out how to properly apply decals with the ballistic gun, but I have no idea how to apply the impact decals with the laser weapon.

Hey @JackieHackera! Welcome back to the forums.

So for your tick function there… That’s a lot to have on tick. Maybe make a few functions out of this, and then have them on an event, because there doesn’t seem to be much reason to update all of these things on tick, when you really only need it while the gun is firing.

Is it a fires-constantly-as-long-as-it’s-held beam, like a sentinel beam? Maybe when you fire it do a loop every so often, like every .25 seconds as opposed to once a tick.

Let’s try to work through one problem at a time! When you try to do multiple things at once, it’s a lot easier to cross wires.

While we wait for your reply, I’m solving your scroll wheel issue so when we get the beam figured out, that’s waiting. :slight_smile:

I have a video of what I’ve managed to do so far in-game, if I remove the first block of code where everything is set on a tick, then the beam either doesn’t spawn or isn’t projected forward. Also the muzzle flash effect is placed weirdly. Thus why I have it set on every tick, but for some reason that’s causing errors and eventually the game starts to lag if I play it for more than a minute.

Hm. That’s strange. So you couldn’t, say, highlight all of that code that’s on Tick besides Tick itself, convert it to a function, and squeeze it in between these two nodes on your fire?

image

Are these pictures all from the same blueprint?

Yes all these pictures are on the same blueprint. The default First Person Player that the editor gives you.


I tried making it into a function and all that happened was this, the beam in the laser went a little down and to the left… I didn’t get any errors or lag, but now I have to fix this…

Hey, that’s WAY better than errors and lag! That’s just a little movement fix.

Any more info you can give me? If you move left? If you move right? If you move backwards/forwards is it all firing from the same location?

Yeah, all fires from the same location, so idk what’s going on. I’m considering just ripping out the laser part of the code, removing the spring arm and target sphere, and just redoing the laser to something easier to code.


Someone advised me to try this “Line Trace” thing, but now the beam is just going to 0,0,0 and I don’t know how to make it go directly straight now…

@JackieHackera No worries. If you take a look at your line trace, that’s exactly where it’s programmed to go, as you can see here.

image

This right here is going to shoot whatever is in the exact middle of the screen. Change nothing else, just plug this in :slight_smile:

Again, change NOTHING else, you are almost perfect with that line trace. JUST add the trace end in this manner. Ignore my empty pins.

Yeah, I’ve had that problem fixed for a long while now… Now I’m working on a method to try and change my player’s weapon based on actors I interact with, but I’m having trouble getting references for a particular actor…

@JackieHackera On the weapon equip, try a forEach off of your weapons array, and do a getClass and check if =class, then if true, do the weapon switch code to that, if false do nothing.

So it will grab everything hit, and then one at a time, grab the class and then if it is a weapon, whatever weapon it is, equip that. :slight_smile:

Thanks
Like this correct?
Screenshot 2022-10-29 101236

Close! You’ll want to use this node instead of your Get Assets by Class, though! It’s under the utility heading, towards the bottom if you type “getclass” in the dropdown.

image


Also for some reason, the line draw doesn’t seem to recognize the actor I placed down? Not getting any collisions there.

@JackieHackera Make sure the actor’s collision blocks visibility, since that’s what channel you’re scanning :slight_smile:

Another problem… Now I need to actually switch the instance of the weapon my player has equipped… And I’m having a problem here… I assume I can just delete the current instance of my player’s weapon and spawn in the new one just like I did in the first image, correct? Or is there a more streamlined approach to this?
(A macro I made that triggers on Event BeginPlay)


(My weapon equip macro)

You are 100% correct on the destruction part. Typically Ammo count and such is stored on the character, so you can switch guns by creating and destroying without worry.

So in the second picture you’re trying to assign a class to an object variable, so yeah that isn’t going to work. You need to drag off of the array element on the forEach loop for that, and set it after the branch, if it gives you trouble go
Array element > Cast to (whatever weapon it’s supposed to be) > rclick and change to pure cast> plug that into your set player weapon.

So I am equipping my weapons, now I need to give them some functionality. The first image is the base weapon class, in which I have the general functionality, and I created a child blueprint that I want to cast the events in the parent class to, but I do not know how… What I mean by that is I want the events to continue on in all child classes, not just one, furthermore I want to expand the code into those child classes instead of putting them all into the weapon class itself.

So anything you would like to change with the Children, go over to “functions” in the my blueprint area, and click the +, select one of those to override the parent capability. Anything you don’t override will make the child do what its parent does, along with anything that is additional that you put in the child BP.