Download

Array of Firing configurations

I’m relatively new to Unreal blueprints but I can code so bare with me.

My Goal
I am creating a 2d top down space ship game. I am trying to use the AttachActorToComponent node to attach the ships turret configuration. I have made a few empty actors (no mesh or code) just arrows for where I want projectiles to spawn, the arrows in these various blueprints have the tag “Turret”. My idea was on firing/mouse click, to use GetComponentByTag to find “Turret” and spawn a projectile for each one. That way, no matter what weapon the player currently has, it will always work. I’m effectively trying to write it so the player can eventually get upgrades like double shot, triple show, diagonal arrow etc and it just switch the configuration by destroying the old config and attaching a new one. Maybe there’s a better way?

My Issue
I need an array of all the possible weapon configurations/actor blueprints. That way I can search the array for getDisplayName == desiredWeapon and add the result to the actor variable currentWeapon. Then use currentWeapon, getComponentByTag “Turret” to spawn projectiles. I tried to make an actor array in the GameMode and it’s telling me I can’t edit it in class defaults.

Can anyone think of a way around my issue or a better way of doing it? I wanted this way as it could evetually lead to modular ships, if I can figure out how to switch in and out components on the fly.

Hi man,
Its a bit messy.

You need an array of all possible Weapon fonfiguration-Actor.
Have you made an array of the right type?
Maybe you dont need an actor reference, you need a ““Weapon-Configuration-Actor”” reference. If you make an actor blueprint, you can have the same kinf of actor-reference

Let me know if you find out, if not post a screenshot please.

By the way:
Be careful that if you plan to have multiple type of werapon active or different cooldown for them,
your search for all actor with tag will be messy.
I suggest you to create a most complex system,
where you save the type of weapon in some variables, to work like slots.
So when you fire, you can check,
the main weapon is active? have ammo? is in cooldown? ok shoot,
The side weapon is too?
if you save reference to the weapons and build the guns firing in different actors , you will get a modular ship game.
Your ship should call
Fire to the Main weapon, with LeftMouse
Fire to sideweapon with Right mouse
Then get the reference to the actor you have there, and you dont know wich weapon is, and via Blueprintinterfaces, say her to fire.
Then the Actor weapon laser, will spawn 60 little energy dots, and then wait for a cooldown of 5 sec before be active again.
the Vulcan weapon wiill shoot always when called but only 4 bullet for second

ooo, maybe i got it now,

Try making Structures
You have to go in blueprint - structures, and make all kind of data, here a sample of arrays.
Basically this structure now is a “default”,
going in any actor and adding a variable of this type, will give them the same list.
If you have multiple kind of things you can also , keep them organized and then, in realtime, merge them togheterr to search for all kind of class.

In the end , another interesing thing.
Enumerators. if you dont know them , sometimes they are useful.