I’m new to coding/blueprints and hoping to get some help. Making my first little game to learn the ropes.
I have a character with health and air stats. His space helmet is broken, and air depletes on a tick until the character finds a space-pod, or dies.
The space-pod is an actor BP (just a plane mesh with a collision box).
In my character BP is an air deplete function.
When character overlaps a space-pod, air is replenished continuously. Air deplete stops.
When character leaves space-pod, air deplete restarts.
In the space-pod BP there’s a Boolean which sets to 1 on begin overlap. Resets to 0 on end overlap.
This Boolean is called from the air deplete function in character BP to switch the depletion on/off.
Now, this all works if I call the Boolean using ‘Get Actor of Class’ and select the BP_Spacepod actor from the dropdown, but the tooltip tells me this is expensive.
However, if I try to cast to the BP_Spacepod and grab my Boolean that way, it won’t allow me to attach an object. I’ve tried attaching the mesh, the collision box, the scene itself. But no dice. What am I doing wrong here?
You’re having a problem here, because you don’t need to cast actually
There’s a misunderstanding, that I think comes from many many youtube vids, that casting is a bit like slinging a hook, and hoping to catch your blueprint.
It’s not. Casting is for checking if a reference you have is of a certain type.
In your case, if you said ‘get all actors of class’ and just specified ‘actor’, you could then loop through them, casting each one until you found your blueprint. Yes, that would be wasteful.
But… if you use ‘get actor of class( your blueprint )’ it’s not wasteful at all. Only maybe if you did it on Tick…
The way most people avoid all this in the first place, is using overap. So code your blueprint with a collision volume, and when it overlaps your player, you can tell them ‘you are getting oxygen’…
This is just one way to approach it from an OK angle. It can still be improved. But now we can place air replenishing actors all over the map and stepping into them gives us air back:
Project link - sometimes seeing it in person is nicer than screenshots: