Hello.
Im wanting to get a reference to a variable from only a “hitactor”.
This is because im wanting a gun system that has most of the shooting side on the player, but is able to recieve the gun stats (damage, recoil, firerate, etc) by simply reading the guns variables.
Ive already got a gun grabbing system setup using linetracebychannel and hitactor, but i cant seem to reference any expected variables because im wanting to access whatever the hit actor is, not any one specific gun.
I also am needing help figuring out how to reference a specificly named component from just the hitactor of a breakhit.
IE: Every gun of mine has a piece called “muzzle”. Im wanting to spawn my bullet at the muzzle of whatever one im currently holding. I already have setup a bool for if i currently am holding a gun, and i have the hitactor of the one im holding, but i dont know how to properlly reference this info in the character blueprint.
I cant just do a normal cast, as that would specify one specific blueprint in the game, rather than whatever gun i happen to be holding.
Example:
Player picks up FN FAL, and their character recieves all of the variables needed from the gun itsself (firerate, damage, etc). The bullets are then spawned with those stats at the grabbed FN FAL’s muzzle.
The player can then drop the gun, and grab an MPX. The variables are grabbed from the MPX, the player blueprint processes them and does the firing, but is able to spawn the bullets at the MPX’s muzzle.
This would allow for a system where i can set up any gun i want and all i need is just to set it up to the trace channel (in this case GunPickup) and to put the variables in the gun. The same could be said for firemodes, i can just setup the firemodes and have bool’s in the guns themselves saying if full, semi, or burst are enabled.
This would make for a very information light (the vast majority of coding is in a single character as opposed to being stored in each gun), very easy to setup system where things could be removed, added, and edited incredibly easily, the only problem being, as i said, it seems i cant reference a blueprint’s variables simply from its Hitactor, nor can i do that for components.
You can get (if valid) a specific component with “GetComponentByClass” of the HitActor. Just put your specificly named component in there (I think it’s all the same class, or?) and if its valid, get the variables.
To Access your guns, you could make a GunMasterActor from wich all other guns derive. Put the gun variables in the master actor and set it in the child guns.
Then you just have to cast to the GunMasterActor if you want to access the variables of a specific gun.
Hmmm.
If i were to use the GunMasterActor method, i would then have to set up if statements for every gun though, right? (IE check if gun is MPX, get MPX stats. If not that, then check if its an MP7, if not check if its… etc etc etc.) And id have to somehow identify that gun, and i dont know if i can get the BP of the gun by hitactor.
What is the desired outcome here is that i can basically just say “take the hit actor and grab the variable with this name”, seeing as every gun would follow a standardised set of names for its individual stats. Is there any way to search for a variable in a hit actor and then reference that variable if it is found?
Are custom item classes possible? Because if not, i dont know that i can specify my guns muzzle unless i was to make it some other random class. Id perfer that both the gun model and the muzzle just be 2 static meshes, though.
Still useful info, though. If this does not work out i will try that. Thank you for responding.
With the MasterGun you could just so that. For example define a variable damage and firespeed and all set the value in the mpx and a different value in mp7.
To get the value, you can just cast to MasterGun and get the variable damage or firespeed. No further checks for different child guns needed.
Ah, okay.
Ill look into that and see how to do it. Thank you for pointing that out, ive spent way too long scratching my head as to why i cant seem to cast variables from a hitactor.
Ive attempted a reload system using this and everything is fine when it comes to how ive set it up.
Problem is im constantly getting “accessed none trying to read” errors on my cast to cast to gun info relay.
The mp7 im attempting to access IS a child of that blueprint.
Any clue why this is happening? i have no event graph errors or warnings.
Tried uploading the blueprints here, but because theyre UASSET files, it says
The attached file is not permitted because the file type is invalid. Seems a bit stupid that i cant post UE4 assets on a UE4 fourm, but whatever.
Are you wanting pictures or the actual blueprint? If your wanting the actual blueprint, ill have to send em thru google drive or something.
Also, it used to work before but now that ive made the MP7 a child blueprint of the guninforelay, the weapon grabbing system is running through everything succeussfully but is not actually welding the hit actor to the grabpoint whatsoever.
Also of note:
Everything runs fine and i get all of the text prints when expected, but the problem is i get errors after pressing stop that say its accessing nothing when attempting to cast to guninforelay, meaning all of the variables pulled from guninforelay are simply “none”.
There is only 1 gun in play atm, and thats the MP7 i sent the event graph for above, so as a temp solution i just tried to have the mp7 set all of those variables right off the bat.
I noticed two things I didn’t know if you manage that anywhere else.
You use the “GunInfoRelay” variable at the cast where you receive an error. Did you set the variable anywhere else? If not, this variable is not set and the Cast will always fail there.
You set your variables in the MP7 Blueprint, do you have the same variables there you also have in the GunInfoRelay? If so, you won’t get the correct values from magsize and bullets left in the mag out of the gun info relay. Instead, you have to set the variables of the gun info relay inside of your MP7.