How to change this cast to blueprint interface

I’m trying to understand more about how blueprint interfaces work, and I would like some help on the best way to replace a cast with an interface.

I create this BPI

And Add on my enemybase, but I dont know what do do now.

I would like to expose the actor class so that I can get the blueprint components that the actor has

Hey @guicamarotto!

Well, to add your functions to the graph you would implement it in the graph by right clicking and typing the name of the function.

However, two things:

You’re trying to cast on an animation blueprint? Totally, 100% ok, as long as you’re casting to the owner of the animation blueprint. The reason casts can be weighty is if you’re casting to things that aren’t normally loaded in memory, it HAS to have them loaded. So, for instance, you don’t want to cast to “Money Pickup” on your player, if “Money Pickup” isn’t always in a level- if it IS, it costs nothing. So casting to the player is generally ok. The other thing is you can end up looping your code if you cast to something to get a function that casts back again, which causes a crash.

Try Get Owner-> Cast to "EnemyThing that owns this ABP → Set reference is actually the best thing to do here. :slight_smile: Then you’re only casting once, and the reference can be used everywhere in the ABP for free.

Hope that helps!

1 Like

cool thanks man. I don’t know if I understood the final part very well, could you show me in a printout what it would look like?

So does that mean that sometimes making a cast isn’t so heavy and is better than what I was trying to do?

That last part is what you already had. :slight_smile:
Try get owner → Cast To (whatever the owner is) → set reference. On Intitialize.

image
And yes, casting has its uses and is often low-impact. In the case where the ABP you’re using will always have the same BP as its owner, it’s nearly nothing, as for the ABP to exist its owner has to exist, so they’re always paired anyway. :slight_smile:

1 Like

oh got it, thanks a lot!

1 Like

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