How to make a collectible power up like in Mario?

Hi I’m making a game where you as a cube that moves through the level avoiding obstacles.

I would like for the player to be able to pick up a power up that allows the player to shoot projectiles and gain one extra hit,
and when hit the plyer have some invulnerability frames.

start by creating a new actor for the powerup. then we will use overlap events to trigger the use of the powerup so in the event graph create a on actor begin overlap event. just after the overlap event you want to determine which other actors can interact with the powerup so use something like a cast to character (or whatever class your player is), this will limit which objects interact to only those youve casted to. make sure to connect the other actor pin from the overlap event to the object in on the cast. the rest of the script will be dependent on the type of powerup.

for the extra hit powerup it will depend on how you set things up. for example you could use the damage system where on hitting a wall you take 10 damage and you have the default health of the player set to 10, in that case the powerup could just set the players health to 20, that will give you two hits worth of health. another method could be just having a variable for how many hits the player can take and you decrement the variable when hitting a wall, its basically the same idea as the damage system. to actually script something like this is pretty simple since youve already casted to the players class you can now access the variable contained within that class and modify them as you like. just drag off the casts “as (insert character class here)” then search for “set (insert variable name here)”.

for the invulnerability powerup you just need to control if hit events are executed. theres a few options here: first if using a damage system you can just disable taking damage on the actor (i dont remember the exact thing to search for off hand). the other option would be to have a check which affects script execution. for example you are using on hit events then you would have a branch, the input for the branch would be a variable which you can toggle called “invulnerable?” and if true then the player cant be affect by hit events.

as for the shooting projectiles. you could have the script to spawn projectiles in the character and just enable its execution like the example above with the variable and branch. Or you could on overlap attach the powerup to the player then enable input to it and have the shooting script in the powerup actor itself.

ill try to make some example pics in a little while.

a few things i didnt mention before are that you are going to want to make sure you factor in the duration of the powerups and make sure that they can only be used once as in they dont stack and they disappear when used (this of course depends on your game but as a generality its something to think about). ive shown a little bit of this in the invulnerability example, there i hid the actor once used (set hidden in game) and i used a delay for the duration of the buff then reset the affected trait before destroying the actor (you may also need to disable collision when hiding the actor).