Call custom event is invalid

hi, i have a custom event ‘Melee Attack Event’ that is located in a different blueprint which has been referenced, this event is causing the error message:

Blueprint Runtime Error: Accessed None trying to read property MyDamageAttack from function: ‘ExecuteUbergraph_ReGoController’ from node: Melee Attack Event in graph: EventGraph in object: ReGoController with description: Accessed None trying to read property MyDamageAttack

Now i managed to remove the error message by adding an IsValid? node before the event but the issue here is that the event never gets called, im assuming this is because the event is invalid.

Any advice on how i could make it so the event can be called?

The IsValid node in pic1 does not have an object plugged in, it will never fire through the Valid pin. You should plug in MyDamageAttack there.

This does not mean it will work, though. The MyDamageAttack object reference is simply invalid (empty, it does not seem to point to any object), how did you reference it?

Creating a reference variable is not enough, you still need to point it to a specific object.

sorry, im new to unreal so im still learning the software. what do you mean? ive used a ‘Cast to DamageAttack’ for my blueprint im referencing.

As far as I know Owner is used in network replication. When it doubt, hook up a PrintText node to CastFailed and see if it triggers. It’s a vital debugging tool.

DamageAttack is an object you created a blueprint for, right? It is a separate actor I can see in one of the tabs. How do you spawn that object in your code? When the player attacks?

it shows the cast failed when i hooked up the print string.

yes, its a blueprint actor.
the object will be spawned when the weapon is equipped.

The ReGoController does not know that.

As soon as you spawn MyDamageAttack object when equipping a weapon, GetPlayerController, CastTo ReGoController > Set MyDamageAttack to the return value of SpawnActorFromClass (MyDamageAttack).

Now, the controller has a direct reference to the spawned MyDamageAttack. And you no longer need to cast anything.

im not sure what you mean. my weapon spawn happens in my character blueprint and is linked to a notify in my animations. What my ControllerBlueprint is currently trying to do is checking if attack is pressed which activates my combat idles in ThirdPerson_AnimBP then continues to go into my DamageAttack blueprint to print a string.

i set it with the Cast to DamageAttack

Isnt that what ive done anyway? ive got the event that connects to the cast and is set to a variable with an object type declared.

every cast iave made has worked this way for my other blueprints, except this one.

i already did, it said the cast failed.

when i press play the string is immediately printed

In your (ReGo) controller there is a reference to MyDamageAttack object. We’ve established that this reference is invalid - most likely because it has never been Set.

Do you ever set that reference? To me it seems that you just created a variable and it’s empty. It’s like creating a float variable but never setting it to any value.

It’s nowhere to be seen in your screenshots.

Let me know if the following clarifies things a bit:

In my pawn I have a CustomEvent (onWeaponEquip) that spawns a new type of attack; now I need to let the controller know about it. In advance, I prepared a variable in my controller that than store the reference to the attack object, currently it’s invalid since I’ve yet to send it an object to hold on to.

I get a controller reference, cast it to my own controller, and set the prepared variable to the return value of the Spawn node.

Now, my controller knows that a new Attack has been created and is storing its reference. The MyAttack object reference will be valid for as long as the object exists - until it is destroyed or I dereference it and let the GarbageCollector take care of it.

If in doubt, in the controller’s Tick check if MyDamageAttack is valid - it will most likely spam invalid all the time.

You mean this?

Hook up a Print Text node to the Cast Failed and let me know what it does.

If you store a reference to the Attack in the character, you can get it from there, too.

You misunderstand what GetOwner does. :frowning: You use that node in the controller by which you imply that MyDamageAttack owns the Controller which makes no sense whatsoever. That’s why it fails.

I’ve mentioned the solution above now twice.

If the character has the reference to the spawned attack, you can get it from there as well.

see, that doesnt make sense to me because there is no spawned attack. im simply holding data in the DamageAttack for my spawned weapon to use

ok my bad, i thought SpawnActorAttack was something else entirely. im trying to set it up but MyDamageAttack only has one pin so i cant link both Cast and SpawnActor to it.

No you’re not. It is invalid unless you set it to a value. Trying to access it before setting it to any value will always result in AccessedNone error, a null pointer. It’s like giving someone address of a building that has yet to be constructed. You have plans for it (blueprints!) but well yeah… the actual structure is not there.

An object reference is a just a pointer in the computer memory. It will point to an object eventually, but you are responsible for doing it.

If you just want to hold hard-coded data, you will be better off with a struct. No need to spawn an entire object just to hold some data. That’s unless you’re planning to give that object some additional functionality.

You may not need to cast it all, look at my screenshot. I’m just casting the controller. See if you can replicate that.

If you’re spawning the attack in the controller already, you do not need any casting at all:

Cast is necessary when you’re unsure what kind of object you’re dealing with. In this case, you just spawned the very object you wanted and can set reference directly.

In blueprints this is referred to as direct communication.

wait what? how do i not cast it and make it talk with another blueprint?

ok, it works! thank you <3