Accessed none when trying to decrement a float

Last question for the night lol. I get an error when I fire my shoot event because I have a decrement float code going off. I have a feeling it has to do with the current weapon BP, but I need that to differentiate each weapon’s values such as current ammo, etc. I tried it with just the structure, but every time I switch weapons the ammo count resets. How can i fix the accessed none error?

Heya TheNME100,

Sometimes there’s some wonky interactions with Decrement and Increment. If you run into this do a float - float node, put in 1 as the subtraction and set the variable again off of that node. It’s silly and longer but it tends to work better sometimes, usually when referencing something else.

As far as the switching, make sure you’re saving the WeaponDetails struct when you switch weapons!

Let us know if that fixes things for you!

1 Like

I tried the float - float node and set members in the structure to the new value but i got a new accessed none. Its because of the set members node now. I feel like it has to do with that saving the weapon details thing you said. How can i go about saving the structure?

Thanks for the quick fire back, @anonymous_user_291a450b!

Are you using the “Set Members In…” Node? It would look like this.
image
If you are, could I get a screenshot for the new code, and another of the “accessed none” message?

Sure thing!

Awesome!

Okay so now we are pretty sure that it wasn’t the decrement at all. It’s the reference!

Try bringing down that “Item to Pickup” reference to right above the “Server Apply Damage” and do an IsValid check on it (keep it connected to the node it’s connected to as well). Throw that isValid between “Server Apply Damage” and “Set Members…” and put in a PrintString with an error message (for you!) saying something like “Hey, you don’t have that reference!” coming out of the False on the isValid.

We gotta make sure that reference is stable, or you get Accessed none!

1 Like

Thank you, so that helps because I now know the reference isn’t stable. Is there a way I could I go about making it stable? It stays unstable.

Progress is progress!

So you need to make sure that the variable in question is being set and filled without a doubt. I’d leave that isValid check in though, because this way you can click fire without a weapon and it won’t cause errors.

So where is the variable Item to Pickup being set? Let’s check that out!

It’s just being used as an object reference variable. I’m not sure how else i should go about setting it up. :sweat_smile:

No worries! You seem to have enough of a grasp of what’s going on.

So what you’ll do is when an Item to Pickup is picked up, you’ll use a dispatcher to call an event on your main character to set it as your Item to Pickup variable. Let me get you some documentation on that.

https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/Blueprints/BP_HowTo/EventDispatcher/

I assume you’re using a parent class for your gun pickups? Set up the dispatcher in the pickup parent, then on your character BP use the Item to Pickup variable you already have and cast it to the pickup parent in begin play to set up your “Bind on…” event. From there - if you can reference the pickup you just grabbed - you can set it as your Item to Pickup variable!
You’ve got some work ahead of you! Get back to us and let us know how it goes, and hit us up if you have any issues!