I’m in the beginning process of setting up an FPS game, and I’m having problems with a weapon pickup functionality which I hope someone can help with. I have a weapon (an AK47) set up as a weapon that spawns upon game start. I have then copied the code in to a new blueprint with a different model (M4A1). I’ve then created an object in game with the intent of destroying the actor that corresponds to equipped weapon and then spawning a new actor in the player hands which then becomes the new ‘equipped weapon’ object. The reason I’m doing this is that then the functions such as damage and rate of fire sit on the equipped weapon object, and the character casts to the weapon to pick up those variables.
Attached first is the code I use to spawn the AK47 at start of game and attach to the player.
I created an object in the world that is the new weapon to pick up.
I then copied the original code and attached it to a keybind with a destroy actor.
I then tried to change the selection in the Class variable in the SpawnActor function from the Weapon_Base blueprint that corresponds to the AK47 to the Weapon_Base blueprint that corresponds to the M4A1.
Although I can correctly get the AK47 to despawn and the M4A1 to spawn in the character’s hands, the new weapon comes with no ammo. I checked and this is because I cannot set the equipped weapon variable to relate to the M4A1 during the spawn actor like I did at the start of the game. I get the error message as seen in the third picture below (ChangeWEaponError): Weapon Base Object Reference is not compatible with Weapon Base Object Reference.
I’ve confirmed that if I change the class in the SpawnActor to the AK47 Weapon_Base blueprint then it correctly works, the old AK47 is destroyed a new AK47 is spawned and comes fully loaded etc.
I assume this is some problem with the way I’m storing my weapons or possibly with the Equipped Weapon variable stored in the character? Can anyone help me get to the bottom of this or let me know if the methodology I’m going through is incorrect?
Any help much appreciated, thanks.