How do i add a relative integer?

Currently im trying to make it work so when the player hits a certain object, the object goes away thats done and then whatever the ammo is currently on +10
However despite what number ammo is on, when I collide with the object the ammo number goes back to 10, but then when i click fire, the number changes to one less then it was before the ammo pick up? :S

For example, I shoot three times so the ammo counter is on 7, I hit the object, the ammo counter becomes 10, i shoot again and it becomes 6.

I think you not updating ammo in character, instead you adding 10 to ammo variable in pickup (which i think is 0 at beginning) and send it to HUD so it displays 10 but when you fire not updated ammo variable in character is send to HUD and displayed… so you ammo pickup only makes HUD display 10 for a moment :stuck_out_tongue:

How do i think I can update it in character then?

You can access PlayerController possessed pawn using “Get Player Character” and then use “Cast to…” to cast it to your class so you can access Ammo

Forgive me im abit confused, am i doing something like in the attached picture? if not what am i supposed to be using for the cast and where within the click event should this be going so that it checks the ammo amount and sets accordingly?

Not in character, in clip so you can add those 10 ammo to cherecter from clip. Keep in mind you want to add 10 ammo to character right?

Clip?
Ammo is an integer that I have in an interface between the Character and the HUD

You are victim of interface myth. Interface is not magical object which allows to do communicate between classes what lot of people thinks… you dont need to do that you can do calls direcly, for example you would cast HUD to your HUD class to access ammo varable in HUD class.

What interface really is its like class extantion which adds common varables and funtions to unrealeted classes, so they can be related and hold in single type varable under that interface. Same as interface in Java or C#.

In otherwords Ammo varable is seperate for each class that implements the interface. Its kind of like 2nd parent class for your classes.

This didnt really help me fix the problem

Problem not fixed yet guys

What class you want to hold Ammo information?

Unless its easy to change id rather not redo the work i have with the interfaces,
but having the ammo information in mycharacter would make the most sense,
it has to be linked to the HUD and a pickup blueprint though

Ok, first undo to state which you have on your image. Ammo in character hold ammo already which is displayed and works correctly -1 on fire, so all we need to make is clip adding ammo. So replace your clip chuck with this:

This circuit takes actor from event which should be your character then i cast it to your character class which should have Ammo varable then i do collision branch as in your circuit. Now i assume you are not aware how to set external variables, grab As Character input and drop it in empty space, it should show your all possible connection you can make with it and search for "Set or “Get Ammo” and there you go you got note setting ammo in character… no interfaces needed :stuck_out_tongue: So you get Ammo varable add 10 and set it ;]

The white link later on goes your HUD interface thing (you didn’t show HUD portion so i dont know what it really do, i assume Ammo input sets the display) and green link you plug to Ammo input. Not sure if it will have update ammo state, if it not display updated ammo plug +10 node instead.

Also note that now cast will also work as a class filter as your circuit didnt had that and would react to other actors touching the clip, this solves that problems as when cast will fail (because touching actor is not your character) it won’t execute rest of ammo giving code.

Thanks iv just done what you said now and got a very interesting result!
Shot off a few rounds again to 7, hit the pick up, the ammo became 0, but when fired it changed to 16,15,14 etc

This is the Ammo aspect of HUD

“Thanks iv just done what you said now and got a very interesting result! Shot off a few rounds again to 7, hit the pick up, the ammo became 0, but when fired it changed to 16,15,14 etc”

If it happens when you pick up it means something wrong in pickup hud update, show me how you connected my circuit with hud update event

The AmmoPickUp on the left, after I set the ammo value I sent it into the interface, where i then call it in the HUD from the picture on the right

Because you send ammo from clip to HUD which now it’s not set at all and stays 0… so i displays 0 :stuck_out_tongue: You need to send Ammo varable from Character which you aready getting in clip blueprint to add 10, send tha tone. Thats why i said to connect Ammo output from my circuit to HUD things oyu made in clip

I already have it so the ammo value in character is set at the beginning and changes after every click, which by the end of the click then gets sent to interface
What do i need to put into character so it will call/read the value after the clip and work it correctly into the HUD

In clip you send Ammo varable from clip (Ammo varable which is part of clip) which is 0 thats why it shows 0 when you pick up clip. But! You already getting character ammo in clip blueprint to add +10 in it (read it twice if you dont understand :p). Look on my circuit i connected ammo somewhere… thats what i wanted you to connect Ammo from character to HUD event thing

And again Interface is not a object, you not sending ammo to interface (Thats invalid statement), you send Ammo varable from clip to HUD using event declered in inteface and implemented in clip and HUD. It’s a main problem, and because you not understanding what you doing wrong (and i explained you what you doing wrong), you having this problem