change actor when killing the enemy (resolved)

hello. How can I change actors when my character kills my enemy?

cap1

here I have the two actors

cap3

inside the goomba

inside mario

so you want to possess a new goomba when mario kills one? what problem are you getting the code looks ok

1 Like

Exactly, the idea is that when I crush goomba it transforms into a crushed goomba actor

Typically, what people do, is animate the crushing, and use the same mesh, just with an animation (blend animation or skeletal animation) that makes it squished.

However, if you have two different meshes, you can do one of two things:

  1. Inside the destroyed goomba, set some flag so it knows it’s destroyed, and then change the “Mesh” property to reference the second mesh.
  2. Call Destroy on the goomba, and Unpossess it from the AIController, then Spawn Actor on the new class, and Possess it with the AIController.

I highly recommend using the animation if you can, and if not, swapping the mesh, not the entire pawn/controller setup.

3 Likes

looking at your code your turning mario into a goomba ha,
if your just changing the mesh then jwatte has your answer above

2 Likes

Thanks for responding, can you be more specific? show graphically why I’m lost like this :grin:

you can get the skeletal mesh, use setskeletalmesh and point to your squashed goomba mesh.

or you could play around with the scale, you could set/lerp the Z scale from 1 to 0.1 might look wonky but would give you a nice smooth transition on lerp

1 Like

I don’t understand what’s unclear. Maybe the confusion is about what an “actor” is, as opposed to a “mesh component” or a “mesh asset?”

An “actor” is a game object that has a certain behavior, can get replicated to networked clients, and so on.
An “actor” doesn’t, by itself, show up on the screen – it needs to use some kind of mesh.
If you want an “actor” to look different, you can change the mesh it uses.
Meshes are typically rendered by a “Static Mesh Component” or a “Skeletal Mesh Component,” which reference a mesh asset of the right kind (Static Mesh or Skeletal Mesh.)
Thus, to make the “enemy” actor render “a squished goomba” instead of “a full-size goomba,” one of the ways of doing that is to replace the Skeletal Mesh in the Skeletal Mesh component from a “full size” mesh asset, to a “squished” mesh asset.

If the squished mesh asset has a different skeleton, you’ll also want to change the animation blueprint to match.
(If you use static meshes instead, the static mesh components has not direct animation, so that doesn’t matter there.)

If you have an AIController, the AIController should probably know whether it is “squished” or not, to stop moving, for example. Or if your enemy subclasses Character, you can set the movement mode to custom, and max speed to 0, which will make it not move.

2 Likes
  • move the collision higher so it sticks out, so we can actually overlap it

image

  • do not possess the new Goomba, you still want to control Mario once Goomba is flattened:

  • put a Print String here (or a breakpoint), to see if it actually triggers:

Do not destroy here, this is the Mario BP, you’ll destroy Mario…

1 Like

we are achieving it. I would only like if it can be achieved as a rebound when colliding with the goomba and that when it is crushed, it disappears in a second later

cap8

Launch the character up, or call Jump. Launch might be better as you might have exceeded the number of allowed jumps at this point.

Great, and how would I make the squashed goomba disappear after a few seconds?

You could Set Actor Life Span, needs no nodes and automatically destroys an actor after x seconds. Search for it in the detail panel of the actor.

Or Begin Play → Delay → Destroy

1 Like

It turned out perfect, thank you very much