Unreal Engine 4 Tutorial - Weapon Switching

  Рет қаралды 56,354

Ryan Laley

Ryan Laley

Күн бұрын

Пікірлер: 113
@alexrusu2905
@alexrusu2905 3 жыл бұрын
I've had a unreal c++ course and had a struggle to implement weapon switching, but now I get it. Thanks!
@matthiaskolley1048
@matthiaskolley1048 3 жыл бұрын
I think I found my new ue4 tutorial youtuber. Thank you so much. I have to check out your other videos.
@RyanLaley
@RyanLaley 3 жыл бұрын
Glad I could help!
@hewhoisme4343
@hewhoisme4343 2 жыл бұрын
@@RyanLaley Definitely my favorite ue4 tutorial youtuber!
@janimusicshorts7707
@janimusicshorts7707 2 жыл бұрын
this is such a good tutorial. I got this to work in one try and that just shows how well you explain things and make it so easy t comprehend. thank you for this great tutorial.
@The_VFX_Guy
@The_VFX_Guy 2 жыл бұрын
For switching, you can mod (%) your current int against the length of the array. Gives you a nice easy looping cycle for your weapons
@bluegizmo1983
@bluegizmo1983 3 жыл бұрын
I wonder if Borderlands has all its 300 million guns equipped and hidden like this...? 😂
@sams_3d_stuff
@sams_3d_stuff 2 жыл бұрын
😂😂😂😂😂😂
@BridgesProductions2024
@BridgesProductions2024 2 жыл бұрын
No, because there aren't actually any built "guns" as such. Each weapon has a "base" that dictates what type of weapon it is, then parts are randomly assigned to it that fit on the weapon.
@Insxne_
@Insxne_ Жыл бұрын
They are created dynamically, this is for games like COD
@pixelAZ_
@pixelAZ_ 3 ай бұрын
​@@Insxne_ Maybe could it be for games like Doom or Quake, too?
@Doubleaa500
@Doubleaa500 2 ай бұрын
Yes!
@unrealper6284
@unrealper6284 2 жыл бұрын
I like that intro/outro
@itanocircus2077
@itanocircus2077 Жыл бұрын
2:33 - If you're attempting to enter GunColor into the Parameter Value and are getting an "Must match exact value", check the variable type of your GunColor. You might have made it a "Color" instead of a "LinearColor".
@naturejacko
@naturejacko Жыл бұрын
thanks!
@VisQo-Herold
@VisQo-Herold 2 жыл бұрын
Took me hours...... Thx man i figured out i could just use PressXYZ and Set Child Actor Class, before i tried to switch between child Actors witch left it invalid and did not delete the old before used BP.... good inspiration :)
@FGK_Capone
@FGK_Capone Жыл бұрын
Ty so much Ryan !
@Mafla-pk8do
@Mafla-pk8do 3 жыл бұрын
Thanks my friend, this will be extremely useful, Thanks a lot!
@An0therR0gue
@An0therR0gue 2 жыл бұрын
I take it that you would need a slightly different system for swapping to a melee from a gun. also, i would like them to pickup the weapon firt to unlock and have access permently afterwards.
@blockout22
@blockout22 3 жыл бұрын
this could get messy real quick if you plan on adding a huge amount of weapons, I'd recommend watching his inventory videos and implementing an equip function to handle attaching the weapons to the player
@matthiaskolley1048
@matthiaskolley1048 3 жыл бұрын
Would you recommend a specific episode? If so: could you please share a link?
@blockout22
@blockout22 3 жыл бұрын
@@matthiaskolley1048 this playlist kzbin.info/aero/PL4G2bSPE_8uktjEdP4ZuRq5r2o4JMdZfM ... probably best to start from the beginning as you might miss something important
@thegiantguy
@thegiantguy 3 жыл бұрын
Just what I wanted to learn today 👌🤙
@JasonErdmann
@JasonErdmann 2 жыл бұрын
Wouldn't it make sense to use Modulo (using Gun Inventory.Last Index) vs testing for IsValidIndex, testing for
@DylanPlayzz87
@DylanPlayzz87 Жыл бұрын
So with this if I wanted to change how each gun shoot, and how each gun works, making one shot like a pistol, the other like a machine gun, can we just change settings inside of each of them children of the original actor?
@ShaddieCakes
@ShaddieCakes Жыл бұрын
This tutorial still works in UE5 btw and really well at that
@tylerpurner2973
@tylerpurner2973 2 жыл бұрын
Very good tutorial, worked like a charm, but how can I check what kind of weapon I am holding so I can add different animations to it?
@cadetquintus
@cadetquintus 2 жыл бұрын
Haven't tried it myself but you can probably make an enumeration of weapon types and add it to the base weapon. Set it for each of the children and on the weapon switch function, grab the enumeration value for the weapon currently being equipped. You'd have to tie that same enumeration to the animation blueprint too of course
@tylerpurner2973
@tylerpurner2973 2 жыл бұрын
@@cadetquintus I already have an Enum set up in the AnimBP but how do I add enums to actors and how would I call it?
@tylerpurner2973
@tylerpurner2973 2 жыл бұрын
@@cadetquintus Oh, thanks! I figured it out.
@petitcoke
@petitcoke Ай бұрын
How can I switch guns by pressing keys instead of using the scrollwheel?
@tlg237
@tlg237 3 жыл бұрын
Hey Ryan, was wondering if you could possibly do a follow up to this about weapon hot keys and binding. I'm working on a game where I only want a player to have 4 weapons equipped at the same time, scrolling can go from 1,2,3,4 and then loop. Pressing the number keys 1,2,3,4 will also swap to the weapon on the wheel. Cant seem to find a very good tutorial on how to do something like this, it would be awesome if you could do so!
@OpenMawProductions
@OpenMawProductions 2 жыл бұрын
@INeedAwesome1 How would you keep it from switching to an empty child actor? For example, if you set all of them to none, and then have pick up items that change the child actors to the proper weapon, what about the slots that are still empty? You don't want to select those, right? Would that just be a matter of using an isvalid? node?
@JasonErdmann
@JasonErdmann 2 жыл бұрын
​@@OpenMawProductions That's a matter of managing your weapon array. Let's say the player starts with 1 gun but can have a max of 4 guns, do you create the 4 slot index or just keep it at 1 slot until they pick up a second gun? If the former then you'd test if the slot's child actor is exists because you know slots 1-4 exist. If it's the latter and you're changing the array size as they pick up and drop weapons, then INeedAwesome1's method would work as long as you do your test for array index is valid. Think of PUBG, certain weapons can only go in certain spots (if I remember correctly), i.e., a handgun is never in spot 1 and 2, just spot 3. So if a player has a sniper rifle and a hand gun, either spot 1 or spot 2 is empty since the user can choose which spot to put the sniper rifle. In this case the array is predetermined at 3 (using video's method) and they wouldn't check if spot 2 (index = 1) is valid, but if spot 2 has an empty child actor. I can't remember how to check for an empty child actor, but it's not too difficult.
@StrannyiQuark
@StrannyiQuark 3 жыл бұрын
Great! Thank you!
@FirstLast-pu9ty
@FirstLast-pu9ty Жыл бұрын
What if you spawn the gun instead of hiding it ? Would that work any better ?
@eggcellentgamedev9689
@eggcellentgamedev9689 2 жыл бұрын
ca you do an expansion on this tutorial for picking up and drooping the weapons?
@matthiaskolley1048
@matthiaskolley1048 3 жыл бұрын
Why are you using an event instead of a function? Is there any advantage?
@iansapp5632
@iansapp5632 3 жыл бұрын
Another way of doing this, instead of having all of your guns attached to the player at the same time, is to just use the "Set Child Actor Class" BP node and swap the gun actor with one of the child gun BPs. You'd have to store your ammo information in an array or something but I would assume this would be better for performance than having the logic of multiple guns always on in the background
@OpenMawProductions
@OpenMawProductions 3 жыл бұрын
Yes, this would be much more performant. It also makes the most sense to put all of the weapon code into each child class individually. Keeps everything clean.
@ArtofBen
@ArtofBen 2 жыл бұрын
In terms of performance it's better to just load it all at once and keep it in memory. Since you are not calling functionality from them when they are hidden the only thing they take up is memory ,but in terms of performance it's better to just keep them loaded.
@ArtofBen
@ArtofBen 2 жыл бұрын
@@OpenMawProductions You don't want to rewrite everything. For example all guns with line traces have what in common ? They are using a line trace thus you don't have that whole bit of logic when you can just change a few variables. Also keeping all of it in memory is more performant . The only downside is that it takes up memory, but in my opinion it shouldn't be that big of an issue.
@OpenMawProductions
@OpenMawProductions 2 жыл бұрын
@@ArtofBen No. This is why you use child actors. You don't want to load it all onto the character and keep it loaded. It's a bad idea. You have so many other things to load and process in the game. The only weapon you want loaded is the one currently in the players hand. Everything else should be in the background. Having a proper inventory system, with a main weapon class and child classes is the BEST way to do it. Not adding everything into the main character and having a huge blueprint spaghetti.
@ArtofBen
@ArtofBen 2 жыл бұрын
@@OpenMawProductions Nobody said anything about not making child actors. I would pretty much never put weapon logic in the player. Make a gun base class and derive from that for the individual weapons. I was arguing against swapping the weapons by destroying and creating another. (Talking about games like Doom where you have a specific arsenal) Keeping all the weapons loaded into memory is just more performant. (Again talking about a game with like 5-10guns) not over 100, but depending on texture size even that might not be too bad.
@PublicUnknownsBattlegrounds
@PublicUnknownsBattlegrounds 2 жыл бұрын
title should be color switching, not weapon switching... for weapon switching you need aimoffsets to be blend along with blendspaces .
@FGK_Capone
@FGK_Capone 11 ай бұрын
I've come to a point where I need an unArmed state using your system but I havent realized yet a way to remove the weapon hand. If you have a solution Id like to see how it's done. :)
@robpenfold9500
@robpenfold9500 Жыл бұрын
Hi, Ryan. How would you handle weapon switching with this method, but instead of just using Mouse Wheel Axis, using the Enhanced Input method and getting the axis value that way?
@robpenfold9500
@robpenfold9500 Жыл бұрын
Nevermind. Figured it out
@OpenMawProductions
@OpenMawProductions 2 жыл бұрын
Ryan, what would be the optimal way to expand this with weapon pick ups and ammo? I'm primarily looking for a Doom or Quake style solution where the pick up only acts to give the player access to teh weapon, not actually attach itself to the player. The reason I want that is I have a distinct material for the first person weapons that prevens them clipping the world, and that can't be used on a "world" model as it would look wrong. Any help would be appreciated.
@Cepaceous
@Cepaceous 3 жыл бұрын
Could someone tell me how I'd implement so that I can actually select which weapons are added to the character at runtime, or switch it while running? I'd imagine that this system wouldn't be ideal for something with a large number of weapons
@lastchancestudiosllc
@lastchancestudiosllc 2 жыл бұрын
Hello, I have done a modified approach to the one in this video that accomplishes your task. Basically you simply have one child actor and then an array of references to all your weapons (weapons need to each be an actor you have set up) then when you switch weapons you simply change the class of the child actor component
@Cepaceous
@Cepaceous 2 жыл бұрын
@@lastchancestudiosllc so, I've actually done something slightly different. When the character begins play, it checks to see what weapons to add to the character, based what's selected in a specific widget. I ran into some pretty severe jank by switching the child actor class like that, and this way you have 2 weapon actors to switch between
@lastchancestudiosllc
@lastchancestudiosllc 2 жыл бұрын
@@Cepaceous yea that would work too. In my game you have weapons that can spawn on the ground as pickups so when you equip a new weapon it basically just changes the mesh for visual effect. The weapons stats are what gets stored in an array. That way as you cycle through your inventory it is simply visually changing the gun and then keeping track of stats in the background
@OpenMawProductions
@OpenMawProductions 2 жыл бұрын
@@lastchancestudiosllc I'm trying to do something similar with mine. I am using a pick up that basically has a cast to the player, checks a boolean, if it's false, it sets it to true and allows the player to select the weapon. (Later it will give you ammo and the like.) I can't get the next stage to work properly though. I'm trying to cycle through the child actors, but only the ones that are unlocked by the booleans. So I made an array of the booleans and i'm trying to check which ones are true and which ones aren't, and if they're true switch to them, if they're not, skip over them.
@ViralLiving
@ViralLiving Жыл бұрын
@@lastchancestudiosllc Hey, I wanted to take this approach, what do you mean by "array of references to all your weapons" like how would i do that?
@V-A-N-G-U-A-R-D
@V-A-N-G-U-A-R-D 3 жыл бұрын
Great video. I have done something similar with setting visibility, but my weapon switching does not implement an input but rather a pause menu option that takes you out of a game very briefly to select a new weapon, and like you said it does not destroy the weapon; it simply makes the player's selection visible and the previous selection invisible. I would like to implement your version of weapon switching as it's way quicker, but I have a question: What input would best replace Mouse Wheel on a gamepad controller?
@florianhulin9932
@florianhulin9932 3 жыл бұрын
On fps frequently the up right button is used, if I take halo on exemple it's the key "Y" on xbox controller, call of duty use the same key and battlefield as well. If you don't use it for other thigs it's seem like a safe choice. On a other way zelda botw use the secondary directionnal key to switch weapon.
@V-A-N-G-U-A-R-D
@V-A-N-G-U-A-R-D 3 жыл бұрын
@@florianhulin9932 That makes sense. Thanks. I just finished doing this a couple days ago.
@Frog423
@Frog423 2 жыл бұрын
how can you do this, but you have to pick up the weapon first, like in ue5?
@pixelAZ_
@pixelAZ_ 3 ай бұрын
This type of stuff It can used for boomer shooter games also?
@OpenMawProductions
@OpenMawProductions 2 жыл бұрын
Hey, Ryan! What about this method with gameinstances? Isn't this going to require substantial amounts of stuff being shoved into the gameinstance so that it can be properly loaded into a next level? Is there a potentially more effective method for say... A doom or a Half-life style game where this data can be tracked level to level much easier?
@rkds1234
@rkds1234 3 жыл бұрын
Hi there, Ryan this is comment isn’t really about this video but u was using the assets from your maze tutorial and I was wondering if I can use them for a game that I publish publicly?
@UltraMonS12
@UltraMonS12 Жыл бұрын
how can i make specifc guns not availaible at the moment and let them unlock when the game proceeds and They Unlock the weapon then show them
@huesado3113
@huesado3113 2 жыл бұрын
Nice video
@ty_teynium
@ty_teynium 3 жыл бұрын
Nice!!
@sezer6200
@sezer6200 3 жыл бұрын
Any chance you can make a video on a save game system?
@zafercangg
@zafercangg 3 жыл бұрын
That would be great
@zafercangg
@zafercangg 3 жыл бұрын
Especially i want to know how to save objects location in big openworld its very troublesome to save them one by one
@SpoodleMonkey69
@SpoodleMonkey69 3 жыл бұрын
Ryan did a 3 part series on save games a while back! I’ve not watched it in a while but I do believe he may have covered saving object locations. If not, I’m no expert but I would potentially suggest adding each object you want to store into an array, then doing a For Each Loop on the array and saving their locations that way! That may not be entirely the correct way to do it but using my limited knowledge, I think that would work!
@zafercangg
@zafercangg 3 жыл бұрын
@@SpoodleMonkey69 that might actually work! Thanks i will try that
@OpenMawProductions
@OpenMawProductions 3 жыл бұрын
@@zafercangg Parent classes are very important fo this very reason. That way everything can be stored and saved all at once.
@cinomontague
@cinomontague 3 жыл бұрын
Shit I needed this like two days ago
@brothersidtv6745
@brothersidtv6745 Жыл бұрын
how to change it for variable sockets? for example its for only righthand socket. if i wanted 2-3 weapon socket for left hand how should i do that?
@drprofhazzmatt82
@drprofhazzmatt82 Жыл бұрын
In the section of the Equip Gun function where you do the AttachComponentToComponent, you specify which socket to attach the component to. In the video the socket name is hard-coded into the node but you could promote the scoket name to a variable and then use logic to determine which socket to attach the weapon to based on which gun you are equipping.
@JoelDiab
@JoelDiab 3 жыл бұрын
When I stop playing, it gives me this annoying warning message saying "root component cannot be attached to other components in the same actor. Aborting" does anyone know how I can fix this?
@ThinDino
@ThinDino 3 жыл бұрын
Just make the skeletal mesh of weapon actor as the parent rather than the scene component
@top_gaming
@top_gaming 2 жыл бұрын
Drag the component u want to attach on to the mesh of the character that has the socket. So if u want to attach a gun to the players hand socket when in the character blueprint component section and drag the gun up to the mesh of the player u will see a green tick
@JoelDiab
@JoelDiab 2 жыл бұрын
@@top_gaming thanks!
@hewhoisme4343
@hewhoisme4343 2 жыл бұрын
What if I want to use this system with like 60 weapons? Is there any way I can reduce the amount of child actors in the character blueprint?
@top_gaming
@top_gaming 2 жыл бұрын
I imagine it will have something to do with having the actors as children to the character so they ha e access to the sockets on the skeleton . They can't use sockets unless they are attached to character i dont know if maybe a data table containing the guns and maybe in the blueprint of character u could make them children if they are picked up or whatever...
@lastchancestudiosllc
@lastchancestudiosllc 2 жыл бұрын
All you need is one child actor component. Then simply dynamically change the child actor class based on what weapon you want equiped. This could happen when a character picks up a new weapon, buys one in a shop, ect.
@Seriesgamplay
@Seriesgamplay 3 ай бұрын
Your video diserve like😊
@50shadesofskittles9
@50shadesofskittles9 2 жыл бұрын
I spelt the parameter gun colour the English way and was wondering why an English teacher would choose the american way ... now I know why! lol
@TriinexHD
@TriinexHD 3 жыл бұрын
Can somebody tell me the logic in order to implement different animations for each weapon + hands based on this tutorial?
@RyanLaley
@RyanLaley 3 жыл бұрын
You can make the animations variables on each weapon
@TriinexHD
@TriinexHD 3 жыл бұрын
@@RyanLaley Thank you worked fine :)
@Anon_2_1
@Anon_2_1 3 жыл бұрын
Im having problems getting the socket locations and rotations. How do i do it. I tried the "Get A Copy -> Get Child actor" and when i attach that to the "Get socket location/rotation" it creates "Root Component" between them. Also tried straight from the "Get A Copy" to "Get socket location/rotation". Im trying to use this in "spawn system at location/attached"
@Anon_2_1
@Anon_2_1 3 жыл бұрын
I got it to work and here is the solution if someone has the same problem: Just get the currently equiped copy with the "Get copy" -> "Get child actor" -> "Cast to BP_Gun" -> "Get socket location/Rotation" and it will get the skeletal mesh between them
3 жыл бұрын
Why not just clamp gun inventory value?
@commoncure3335
@commoncure3335 Жыл бұрын
so i plugged in a print string node on the mouse axis input event and it shows that it ticks continuously. is that normal?
@drprofhazzmatt82
@drprofhazzmatt82 Жыл бұрын
As long as you are actively scrolling, you are continually firing mouse axis input events.
@cosmicnova5731
@cosmicnova5731 3 жыл бұрын
Nice
@VVaypoint
@VVaypoint 3 жыл бұрын
When I set Print String Text Color to Gun Color it won't work anymore. Otherwise works great. Any clue why?
@yamoma6580
@yamoma6580 3 жыл бұрын
Couldn't figure out what I was doing wrong until I saw this comment, so thank you, but I would also like to know why.
@gabenager5909
@gabenager5909 Жыл бұрын
everything worked until I added the GunColor to the TextColor in the printstring (the final step) then the text just didn't appear, I double checked everything in the video and I don't know what I did wrong, keep in mind, it worked perfectly up until this step
@itsalwaysoniontime
@itsalwaysoniontime 2 жыл бұрын
collapse to function failed 14:06, please can someone help me
@OpenMawProductions
@OpenMawProductions 2 жыл бұрын
...This doesn't seem to actually change weapons. One of my children has a shoot function that is setup to fire a hitscan, and when it changes to the next weapon it is still firing the same hitscan as if that weapon was still there. EDIT: Nevermind. But for some reason my scrollwheel is not switching the weapons. Very strange.
@LFPaiser
@LFPaiser Жыл бұрын
In my case I forgot to link the exec path (the white line) from the mouse event to the first branch
@reaperzx3ify
@reaperzx3ify Жыл бұрын
doesnt shoot the bullets from the gun it should just the 1st one
@ThinhNguyen_39
@ThinhNguyen_39 3 жыл бұрын
niceeeeeeeeeeeeeeeeeeeeeeeeeee!!!
@blaiseandthebambina
@blaiseandthebambina 2 жыл бұрын
Thank you for the video but I think this particular tutorial isn’t as helpful as your others. This scenario of hiding guns isn’t utilized in real games and therefore doesn’t steer newer Unreal users in the right direction to implement weapon changing properly. Love everything else I’ve seen of yours though!
@OpenMawProductions
@OpenMawProductions 2 жыл бұрын
Any suggestions on the better way?
@Cplusplus745
@Cplusplus745 2 жыл бұрын
@@OpenMawProductions There is another tutorial in this channel based on container classes that is amazing but kinda difficult. kzbin.info/www/bejne/b2WroZinocx-d9U
@MaxStudioCG2023
@MaxStudioCG2023 Жыл бұрын
what if you have slots for the Equip in hadn and equip in the back or on hip ..and unsing animation to anim the equip unequip ....or when ppick up weapons from ground and you want to switch with buttons 1-4 or mouse scrol ......this tutorial wont work if have custom events for each blueprint spawned actor and animations all that ....
@mr.raider744
@mr.raider744 3 жыл бұрын
HI ! this tutorial was really helpful, but it was buggy when i tried it in my game because of the ammo counter... so i would really be thankful if someone helped me fix this issue, the thing is when i switch weapon the sound effect and the ammo counter doesn't change at all and its like i'm shooting with the same gun but with another model
@OpenMawProductions
@OpenMawProductions 2 жыл бұрын
You have to set the sound effect and all the data in each weapon child, not the base weapon. Everything in the base weapon should be blank or a default value.
@pachyrhinosaurus1
@pachyrhinosaurus1 2 жыл бұрын
Attaching the child actor how the fuck you could that
@nitinnishad4810
@nitinnishad4810 2 жыл бұрын
How to do this in Multiplayer? Anyone?
@gamekheloindia4503
@gamekheloindia4503 8 ай бұрын
Hi bro can you give me animation pack for free please please please please please please please
@zafercangg
@zafercangg 3 жыл бұрын
4th comment
@johndoe35717
@johndoe35717 2 жыл бұрын
your video is so short and snippy hard to follow
@johndoe35717
@johndoe35717 2 жыл бұрын
dislike
Weapon Switching In Unreal Engine
14:01
The Game Dev Cave
Рет қаралды 3 М.
Epic's Unreal Optimization Disaster | Why Nanite Tanks Performance!
13:07
Threat Interactive
Рет қаралды 233 М.
У вас там какие таланты ?😂
00:19
Карина Хафизова
Рет қаралды 23 МЛН
Это было очень близко...
00:10
Аришнев
Рет қаралды 7 МЛН
Motorbike Smashes Into Porsche! 😱
00:15
Caters Clips
Рет қаралды 23 МЛН
I Learned Blender in 30 Days
14:15
OverPhil Dev
Рет қаралды 198 М.
I Wish I Had Known This Before I Started Unity Game Development...
11:11
Weapon wheel tutorial - Unreal Engine (Part 3)
25:51
JeeDev
Рет қаралды 6 М.
The Mojang ARG You've Never Heard Of
21:38
RetroGamingNow
Рет қаралды 179 М.
3 Hours vs. 3 Years of Blender
17:44
Isto Inc.
Рет қаралды 5 МЛН
Why Unreal Engine 5.4 is a Game Changer
12:46
Unreal Sensei
Рет қаралды 1,3 МЛН
I Optimised My Game Engine Up To 12000 FPS
11:58
Vercidium
Рет қаралды 712 М.
Unreal Engine 5 Tutorial -  Grenade Aiming
25:26
Ryan Laley
Рет қаралды 8 М.
У вас там какие таланты ?😂
00:19
Карина Хафизова
Рет қаралды 23 МЛН