Weapon swap using SetchildActor()

I am swapping weapon class in the child actor component. everytime i switch, the ammo and maxammo also resets itself. i have stored the all the weapons classes in an array and just changes the index when switching the weapon and store it to another variable of TSubclassOf.

TSubClassOf<ASWeapon> holds a class type, not an object with a class that derrives from ASWeapon.

So what you do is create a new weapon every time instead of using the one you had, that’s why the variables are reset.

ohhhh got it thank you very much. is there a way to create and object of that class and and then do the swapping. i know how to do it with the pointers. just want to know how to implement the same functionality using childactorcomponent.

I must admit I don’t really have experience when it comes to weapon systems, so my ideas may not be the best or most efficient.

But of the top of my head, if you’d really want to stick with the child actor component, you could include the variables for your weapon in a struct too. and set these every time you switch the class of your child actor.

Personally I’d use completely separate actors and attach and detach them to the character using AttachToComponent or AttachToActor and specify the weapon socket name on your character.