Is there a better way to code this? I’m wanting to have it loop thru 10 upgrades and feel like this is very costly
You want to just change to the next weapon up?
If you had the classes in an array, then you can just change the index.
So its a top down arcade style game, where the enemies drop power ups. When you pickup a power up for the same type of weapon I want it to shoot from another muzzle.
If you know what it is you want, and keep searching through an array to find it, a Map is usually the right answer.
That being said, it sounds like this just runs once when you pick something up. Are you sure this is a problem at all? Is there a hitch when you pick up a power-up? And, if there is, are you sure this loop is the culprit?
(Btw, you don’t show the full loop, so it’s very hard to tell what you’re really doing and how to re-structure it if needed.)
I dont have anything in a loop yet, I would like around 10 upgrade variants and have no idea how the best way to that.
Currently on pickup it applies the new gun and deletes the old one and the pickup is the same as the current gun, it will upgrade the gun to the next level.
It is impossible for me to understand what question you actually want answered.
Building 10 different models for a weapon for 10 different levels of upgrades is totally normal.
Replacing the current weapon model asset with a new weapon model asset when you upgrade the weapon is totally normal.
Just make sure that you pre-load the assets when the level starts, so you don’t get a loading hitch when you collect the power-up.
What symptom are you seeing that is not working right?
I’m so new I don’t know the standards yet, so that was my main question (if there was a better way of doing than how i am)
The part where I am stuck, is that when I load the new gun, it jumps to the final form of the upgraded gun, i dont think i have my branches set up right. because it will jump from lvl 1 to lvl 3, skipping the middle part
What I would do:
- Create an
Array
ofStatic Mesh
asset references as a variable on the blueprint - Add each model to the array in order from lowest-level to highest-level (in the defaults for the variable)
- Add an
Integer
variable calledLevel
- Build a function called
LevelUp
that does something like:
a) set theLevel
variable to theminimum of (length(model array)-1, Level+1)
b) get the mesh asset reference from the item at indexLevel
from theModelArray
c) update theStatic Mesh
asset reference in your gun Static Mesh Component to be this - when overlapping the pickup, delete the pickup object, and then call the
LevelUp
function