Accessed None trying to read property

Can I fix this?

here is full error message :

Blueprint Runtime Error: Accessed None trying to read property CallFunc_K2_GetRootComponent_ReturnValue4 from function: ‘ExecuteUbergraph_ThirdPersonCharacter’ from node: AttachToComponent in graph: EventGraph in object: ThirdPersonCharacter with description: Accessed None trying to read property CallFunc_K2_GetRootComponent_ReturnValue4

Hey there, you are doing an is valid branch for sniper bp (and rifle bp), on the false branch (which means its not valid) you try to access it anyway. That’s why it’s giving that error.

If I understand the code correctly you’re trying to change where the weapons get attached (either armed or unequipped on the back)? Now basically what you are stating through the “is valid” check is that “If we dont have a reference to the weapon, we still try to use it”. This goes against programming logic and will give you an error in terms of an null pointer exception (i.e. the variable Sniper_BP is pointing/referencing to an empty object). Therefore you will not be able to do “AttachToComponent” because you basically do not have the weapon to attach with.

What you probably are looking for is building up some logic revolving around a very simple “state machine”. This could be done through an enumeration that holds many different weapon states(armed, onBack etc) (A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums)

So when you do the “Is valid check” and it is true (remember the weapon variable needs to be valid for you to be able to operate on it) you can use a switch with your Enum to attach your weapon based of of the state of the Enum.

I can attach pictures later if you want to!

Cheers!