Print String on Cast to Node

Hello again. Definitely a noob question, but when trying to work out some logic chains for how I can get my events to print string under certain scenarios, this is the issue I’m having at the minute:

In my level blueprint, on event tick, I’m using a ‘cast to’ node to get a reference to my enemy that exists in the level. Said enemy actor is in my level, yet the current print string I’m getting on an event tick is always failing, I would think in this case as long as my enemy actor is active and present in the level then it would always pass success, what am I missing here?

I know that using an event tick in a level blueprint isnt the most optimized approach, but this was just for the sake of testing some logic.

I think maybe get owner isn’t returning anything?

What is a ‘northwood_UE5’?

That’s the Old West Learning UE5 map from the marketplace.

What do you suppose might be an appropriate object reference to give to that actor class just to have a reference to it if get owner isnt right?

No, I mean, what sort of actor has this code in it? Is it something that has an owner?

Drag the reference from the Outliner to the LB. Or select the actor in the scene and create a ref from the right click context menu. No need to cast.

Owner will definitely not work, because that’d be something that owns the level - not sure what that would be.

Doh… :sunglasses:

Didnt work sadly, still cast fails.

Here’s your reference.

The problem with doing it like this is now there is no logic to tell it which print string to use, the cast success or fail which was the point of trying to use a cast to node.

For 3rd time… no need to cast - read the blue note :innocent: This will never fail, the fail condition will never trigger (unless the actor is removed from the game). Perhaps there’s some confusion here regarding what casting is for…

as long as my enemy actor is active and present in the level

If this actor can be destroyed, use:

image

1 Like

I was missing the part about using an Is Valid node, I forgot about that one! Seems like that will do it, apologies - I am new at this!

1 Like

Technically, this should work OK and would fail were you to destroy this enemy:

It’s just utterly unnecessary. Validation seems more straightforward.

Good luck!

I think the original reason my inclination was to go for a cast to is because Id like this to apply to any actor of that class, maybe there is still a way to do that without trying to have a reference to just the very specific one that exists in the world outliner.

Not sure I understand. Cast To does the opposite - it’s a test, a filter, a type conversion mechanism. When you cast, you test if the object reference is of Enemy type. That’s it.


If you want to interact with multiple classes, look into interface communication.

I see what you mean and it looks like I had it backwards then, in any case this is the solution: