Cast To.....

Hello All,

I do not know why I struggle so much when I need to cast to something that is not the Player Character…

I am trying to cast to an Actor Comp0nent called “Trace Component”. For the life of me I do not know what to choose as the “Object”…

Any help is appreciated.

What is the trace component in? The player?

If it is, then you would do ‘get player character’ → cast to your player type → drag trace component → get sword ref

The Trace Component resides in both my player character and Enemy Base character.

I am able to call from the player character perfectly. I am just struggling calling from my Enemy Base Character (which by the way is the parent).

Ok, but you’re in a widget there, aren’t you?

yes Correct. I am trying to call from inside a widget.

Is this some sort of character choosing widget?

You can’t reference the internals of actors that don’t exist :slight_smile:

If you want to cast something, you need to have an actual actor reference to cast. In other words you need at least one instance of your enemy base character.

Maybe if you tell me what you’re trying to do? ( generally )

Appreciate your willingness to help.

The widget will basically animate text above the damaged characters with the amount of damage. Kind of like floating above the head.

The WeaponDamage comes from the equipped Weapon. From the Trace Component I call the Weapon Damage and when a hit is detected applies damage.

Now… I am able to get this to work for my widget when it is the PlayerCharacter. I simply cast to my Player Character and the finds the weapon damage from within the TraceComponent.

I need to do the same thing coming from the Enemy but when I call to the Enemy Blueprint, the cast “fails”. My guess is I am calling from the wrong Object.

1 Like

Now we’re cookin… :slight_smile:

So your player and your enemy both inherit from enemy base?

Rather than trying to find out what kind of actor the widget is floating over, why not just pass an enemy base reference to the widget?

That way, both the player and the enemy just pass ‘self’ when they make the widget.

I tried doing that but I get this blue warning and then it doesn’t work.

The cast still fails.

The reference you made is empty , maybe use get actor from class to find it in the map your enemy base thing . It need to have a source .

Sweet Dude, that did the trick, THANK YOU !!!

1 Like

So I discovered there is still an issue. I took the suggestion of Get Actor from Class and and it first it seemed to work.

But then I realized that it only grabs the first actor but seems to ignore all the other actors of the same class. Here is the strange part. After hitting that first actor on the level, all other actors of the same class seems to work.

So I feel like I am back to trying to Cast to my BP_EnemyBase again, but to which Object ?

Just to add some more info, the reason why I am casting is that I need this variable IncomingDamage that resides on BP_EnemyBase. This is what is feeding the Floating Text numbers.

One last thing, BP_EnemyBase’s Parent class = “Character”, not “Actor”.

LOL, OK I found my own solution so I will share!

I ditched Casting all together. Instead I turned my FloatingText into a Custom Event then added an input called IncomingDamage.

Then from my BP_EnemyBase, I fed the IncomingDamage through my widget.

Whew !!

You can expose vars on widgets:

image

So you can:

image

No need for another event, just use the var in Construct.