How to make an array for actor obj or class?

In a Beat Em Up style game, I want to check if there is any weapon in the screenbox (screen size box collision), and if so, the NPC’s will try to go for them instead of going to the player.

I imagine I will have to make an array and some how connect all those actor blueprints (each weapon has its own blueprint) to it.

I see where to make a variable into an array, and even add inputs at the bottom, but I can’t seem to get it to select those actor bp’s. And do I need Object Types - Actor - Object reference OR class reference for what I’m trying to do? Thanks

1 Like

Just use ‘get all actors of class’, with the class set to your parent weapon type.

It will give you an array of actor references, which your NPCs can use to go and pickup the items.

1 Like

When I made these weapons they don’t have a parent. It list the parent as just “Actor”. Is there a way to give them a parent? Or what can I do here?

You can make an empty actor blueprint, and then use that as the parent for all your weapons. Much easier to catch them all with the ‘get actors’ node :slight_smile:

1 Like

Ok I have created an empty blueprint (called WeaponMasterDummyBP) and added child actor components and set them accordingly to look for each weapon bp.

But what would you suggest to check if ANY weapons are overlapping the “screenbox” (which is inside the camera actor btw and moves parallel with the tpc), and if so, that would I think have to set an NPC on like a “quest” to try to go to and pickup / attach the weapon.

I suppose once even one NPC goes for one weapon, that weapon then would have to have something set so that no other NPC seeks for that same weapon.

Any help is greatly appreciated Clockwork, thanks again!

No no :slight_smile: Sorry if it wasn’t clear.

Just make the empty parent BP, and in each of the weapons. You don’t need to change anything else.

Then, you can get all of your weapons in one go

image

1 Like

Ahh ok I see it now, that wasn’t too bad. I have that get all actors of class plugged into a For Each Loop. When that checks that, will it be going through all the children names in alphabetical order or how does that work?

It will give you all the weapons in the level, random order.

You will still need to cast to the subtype, to get at the functionality and variables, though.

1 Like

Ok thanks. Would you do it like this with a sequence node?

I moved three weapons into the starting position just to see if it worked. Seems to have worked. It shows for 2 seconds and then disappears I guess that is the default setting for a print string.

Ok now I will have to figure out the next part about assigning an enemy to get one or go after it. Any ideas here lol?

Yes. But you don’t need this bit

image

You can go right from the cast into the print :slight_smile:

All the stuff that’s common between the blueprints, like how you pick them up and put them down ( or stuff like that ), can just go in the parent. So you only have to write it once.

For instance, that ‘available’ bool. You don’t actually need it, but if you did, you put it in the parent.

1 Like

You have to put it in the AI code, but that’s not really my area :wink:

1 Like

Ahh, and it would show the weapon name?

Ok will keep that in mind.

When you say I don’t actually need that variable, can you expand on that info?

I hear ya, Enemy movement behavior seems really complicated. Some nights I can stare at the screen an hour and still get lost in it haha.

1 Like

Well, you might need it, depends on that you’re using it for.

The code would work fine like this

Repeating yourself, is the sign that stuff needs to go in the parent. So, if you always want to know if a weapon is available, the bool goes in the parent. Then you can say

The great thing is, it’s also in the child, because it’s inherited from the parent

image

1 Like

Thanks for all the well made replies Clockwork! I got to run now, be back on this later.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.