Collide with an Actor Class?

Hi! I’m in the process of trying to make my first game from start to finish in Unreal Engine 4 – I want to create a bunch of chickens, and if the player (using 3rd person blueprint example) collides with any of the chickens, you lose. I believe what I need is to create a blueprint class for the chicken so I don’t have to script each chicken individually and can spawn them easily. However, now that I’ve created the class, I’m a bit lost. Don’t I have to take care of this in the level blueprint so that I can display a gameover screen? But I don’t know how to refer to “all chickens” – the only thing I know how to do is create a chicken in the level and reference that in the level blueprint. If anyone could help me out here, I would greatly appreciate it! :slight_smile:

  • you can manually add chickens to an array via *MakeArray *node
  • you can *GetAllActorsOfClass *(Chicken)
  • you can *GetAllActorsWithTag *(Chicken)

In all 3 cases, the returned pin will be an array, *ForEach *loop will allow you to iterate through its elements and give you a chance to perform poultry operations. [HR][/HR]
You do not need to manually place the birds in the Level. You can spawn them dynamically (in random places, for example), too - do *a ForLoop > SpawnActorFromClass *and then add them to an array as you iterate. Once you have an array, you can use loop operations to access each and every object the array contains.

Another method involves a dispatcher and registering the chicken actor events. Dispatchers can send information to anything that has registered with them.

And there’s *Interfaces *but it might be too early for that since we do not know how vast your bestiary is supposed to be.

I shouldn’t be using the GetAllActors every tick, though, right? How do I use the array for collision events? Sorry, I know this might seem like a small leap but I don’t really know anything about blueprints :l

My main goal is to have a bunch of animals of a few types (maybe three or four) roaming around, and if you collide with any of them, it causes an event to happen. I tried adding a capsule trigger volume to the actor, but I have no idea what to do with it.

There should never be a need to, no. You can do it at Begin Play, or after the level loads and you begin playing. You can use it to gather actors together and place them in an array.

You do not use the array per se. You asked how to get access to all actors in one go - through an array.

To collide with any object in the level you do not need to keep them in an array. Your objects need collision, you can use the static mesh as is or add a collision volume. Those components come with a bunch of Events build in.

What you really want to do, is to have the player initiate the collision here. So you could have a chicken object like this:

And your player can interact with that object like so:

Yesss, that overlap event is the kind of thing I was looking for – thank you :smiley: I couldn’t figure out how to get there. Also, I really do not understand the concept of casting. I still copy those things and try to use them as best as I can, but I don’t understand how they work.

If you expect some complexity here, you should consider inheritance. Create a base Animal class encapsulating common functionality - Eat, Walk, Chase, Die. And then extend this class if some animals need unique abilities; you may have an animal class that needs all of the above but can also Fly or Swim. So it will inherit abilities from the base class and have its own, unique methods and variables on top. Or it can even override (replace / modify) the existing behaviour. Chickens will *Peck *instead of eating, *Strut *instead of walking and explode in a feathery fireball when they Die.

chick.png

In this case *casting *is like asking the object you run into: “Are you a chicken by any chance?!”. If the answer is “Nope”, the cast fails and that’s ok - the player collided with a tree (for example) so there’s no need to do anything.

Haha, that’s a really funny yet effective way to think about it – I won’t forget it XD Thanks for that.

That’s really good to know about the animals. This is a pretty rudimentary demo project, so I can simply create a child blueprint class for each animal type and simply change the model.

One thing I wondered when implementing what you showed (thank you so much for the pictures, by the way), is there any way to have the On Component Begin Overlap commands in the level blueprint? I tried it there first but it didn’t work. When I moved it to the Third Person Character blueprint, everything worked fine. One reason this is a problem is because I want the event to trigger the enabling of a postprocess volume, but it can’t find the postprocess volume because it is in the Third Person Character blueprint. There’s gotta be a way to communicate between those blueprints…

That would work, yes.

Yes, it’s possible. You can place Trigger Boxes and have their Events fire when things overlap them - think area trap or a healing zone. Or a chicken coop that spawns chickens when the player enters.

edit:

Accessing framework classes (game mode, controller, character and so on) is pretty straightforward and can be done from pretty much anywhere, like so:

The other way round, sending information *to *the Level Blueprint, is a tad more complicated but can be done, too.

Well, what I meant was, can I have the “On Component Begin Overlap” command of the character in the level blueprint? Because as it stands, I can’t access player collision with another character and the postprocess volume in the same blueprint, as far as I’ve seen. Is it possible to create a custom console command and then call it from the level blueprint???

Yup:

However, avoid scripting in the LevelBlueprint. Unless they’re level specific behaviours.

Thanks, and thanks for the advice there. Good to know those things too :slight_smile: Ahh, I should’ve figured the solution earlier would be casting… XD

Sorry for the noob question, but I can’t figure out how to get the Target → Post Process node on the second to last picture. If I put in the postprocess volume as a variable, its pin is on the right side.

Nodes are context sensitive, drag a wire and then search:

That option literally isn’t there for me, tried context sensitive and non-context sensitive.

​​​​​​​

Does your character have a post process called post process? You can’t access something you’ve yet to add.

Perhaps you renamed it.

Sorry, what I meant was, I can access one of the level’s postprocess volumes in the Level Blueprint, but I can’t access it in the ThirdPersonCharacter blueprint. Meanwhile, I can’t (or at least, wasn’t able to at the time) handle collision of the ThirdPersonCharacter outside of its blueprint. Is there any way to reference a level postprocess volume from ThirdPersonCharacter’s blueprint?

This is something that you should avoid, ideally. Something that is level specific can be handled inside the LB. You have access to both elements there:

Capture.PNG

So you should be able to just utilise #10.](https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/1544606-collide-with-an-actor-class?p=1544673#post1544673)

How is this interaction going to look like, what triggers it? Player collides with something and changes post process? #10](https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/1544606-collide-with-an-actor-class?p=1544673#post1544673) it is then.

Hmm, I still couldn’t get the PostProcess to show up in the level blueprint as a drag option. I had renamed it, sure, but I tried what you typed, and also its name, nothing showed up with or without context sensitivity :l

Never mind, I’m a dumb-dumb – I realized I don’t need to get that to work because I can now just refer to the postprocess the way I normally would. Sorry about that, thanks for putting up with me and I really appreciate the help :smiley: