Cast failing

Hello
I’m having issue with trying to cast an Actor BP into another BP
I created a new variable selecting Actor Object reference to link to object on the cast node
but the cast keeps failing

any hint ?

Creating a reference variable does not magically create an object, nor does it automatically point to it. Where is the object this variable refers to?

Assuming you’re talking about projectiles, what if there is hundred of them? How would you choose which instance to cast?

Best explain what you’re trying to do.

First thanks for your answer
I know it’s a noob problem and i’m doing/thinking it the wrong way

i’m trying to do a weapon upgrade when then player overlap the item the damage done by projectile should be x2


But that’s not what you’re attempting above. You’re trying to change the damage of 1 single projectile that is in flight or the one that the player carries in their inventory. Hard to imagine how it’s suppose to work without knowing more.

i’m trying to do a weapon upgrade when then player overlap the item the damage done by projectile should be x2

One projectile or all future projectiles?

Some questions first:

  • is the upgrade global (all projectiles), or one only? If so, which one? Current in flight, next, something else?
  • how and where do you spawn the projectiles?
  • who fires them - the gun or the player?
  • if the gun fires them, where is the gun?

This may be unrelated but I’ll ask:

  • UE already has a native damage dealing system:

image

Are you using it? As this seems like a custom solution:

image

Does it mean the upgrade needs to fit into some system you developed (and we know nothing about)? Or perhaps this serves another purpose?

One projectile or all future projectiles? i want to upgrade all future projectiles

Some questions first:

  • is the upgrade global (all projectiles), or one only? If so, which one? Current in flight, next, something else? >> All projectiles

  • how and where do you spawn the projectiles?

  • who fires them - the gun or the player?

  • if the gun fires them, where is the gun?

Projectiles are spawned by the Gun BP



i’m trying to implement everything myself for learning purpose so i’m not using apply damage function i’m sure i’m not doing it the best way but i think i’m learning more that way

Thanks again for your time

And the gun is a Child Actor Component owned by the player:

Cool. I’ll assume you’ve already set the value of that variable correctly. In case you have not:


trying to implement everything myself for learning purpose

Sure, why not. My suggestion is to pick your battles carefully, though - consider embracing established solutions rather than reinvent the wheel. The native damage system is robust, surprisingly flexible and the basic usage is trivial.

In the projectile:

when the projectiles hits, it deals Projectile Damage to Damaged Actor

The above will expose a new float pin on the Spawn Actor from Class node when the gun spawns a projectile actor, we can pipe in new data there. See below.

In the gun:

when the gun spawns a projectile, it feed its data to the projectile:

image

I added a new variable the player will modify when they run into the damage box. This would upgrade the gun.

In the player:

when the player runs into a damage box, we use the boxes multiplier to amp up the damage of the gun

Any actor that needs damaging:

image


Avoid allowing random objects access the player:

Not sure what the rest of the plan is, I see a WeaponStruct inside the Damage Box actor. Seems a tad strange but might be fine, who knows what you’re up to. :innocent:

There should never be any need for that.

I think you are right and i just reinvented the square wheel lol

That cast to damage box from player character BP is also failing i dont get why …

when i cast to player BP it works fine but any other cast is failing i tried casting from other BP to test it and all are failing …

otherwise everything is working fine player movement, animations, firing, ennemys taking damage and diyng

when i cast to player BP

This script should be in the player BP. Are you sure you didn’t put it in the box bp?


It’s suppose to fail until you enter that specific box type. What actor are you overlapping then - print its display name.

yes it’s in the player BP

Display name returned is BP_Dmgx3 (?? why 3) I have no BP_DmgX3 but BP_DmgX2

bbb

EDIT : i deleted all nodes and recreated now display name is BP_DmgX2 as it should be

i was still getting this error

Blueprint Runtime Error: “Attempted to access BP_DmgX2_C_1 via property K2Node_DynamicCast_AsBP_Dmg_X2, but BP_DmgX2_C_1 is not valid (pending kill or garbage)”. Node: Set UpgradeProjectileDamge Graph: EventGraph Function: Execute Ubergraph BP Hero Blueprint: BP_Hero

so i inserted a delay before destroying the damage box and now it works

thanks again for your help
learned a lot :smiley:

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