How to set Variables on Client?

How do i set a variable from executes on client?

I can seem to make anything else work, except for setting variables. Can someone please explain this to me?

You can do this from either a custom event or a function created in the functions panel or even off EventBeginPlay or any other initializing node if you are using any blueprints. You need to create the variable in question in the variables panel and the drag it into the event graph and select “Set”. And connect it up to your function or event. You can the call that function from anywhere else in that graph or another blueprint, by casting to it’s parent class.

1 Like

So, Ive tried all of that. Maybe it is setting the variable, and not calling from GameInstance. Perhaps i am confused.

Either way, it is Not functioning properly.

You need to hook up the node from your cast to the variables you set. You init base variable stats event is hooked up, but not the one from your game instance cast… it’s the top arrow on the right side of the cast node. Try plugging it into your camera field variable.

it SHOULD be doing that in beginPlaySR, i think?

Well, that is so but your execution stops at your cast because it’s not feeding into the variables you set… You’re getting the variable correctly, but you need to hook the cast up to set it.

hm, how so?
it resumes excecution in beginPlaySR.

Sorry, maybe you dont notice. but it is connected. i kindof truncated most of it, but, if you look at the bottom of the image, you can see how the first one is linked up to the cast node.

Sorry I’m only on the phone so the markup is trash, but you gotta hook up that top right node to the set variable…

Additionally you need to also cast separately on the right side event also to properly get the variable on that logic as well.

so, this is not a possiblility? Im kindof new, and dont know all the intricacies.

it works on server, but not client. so it leads me to believe yes.

EDIT: it works on the listenserver server, but, as a client connected, it does not.

That is where you are calling the function and it looks about right, but in that said function it is casting correctly, but the chain of events are broken because they’re not hook up… you need to cast on the right side event to your game instance also. You’re just missing that one connection point in the actual function.

Im not sure. like i said, it works on the server side of the program. just not the client.

Actually taking a closer look, you may not even need that function that calls your game instance unless you’re using it somewhere else, but the cast is not happening on the init set base. Just move it into that function and hook it up. Lol. The node just isn’t hooked up. There’s no way around that. Just right click on the “AsBpGi” and convert it to a pure cast since youre not able to hook it up lol.

Edit: I’m explaining this poorly from my phone. If you hadn’t figured it out, when I get back to the PC I’ll send you a better example.

If its not hooked up, then I don’t understand why it functions on serverside.

It is split like that, because one casts from server, and the other is trying to write vars to client.

It may be accessing the default variable, but it’s not getting that variable from the game instance directly 100%. I’ll get back in 15 minutes with a good explanation with screenshots

actually, the default variable would mean 0. so, it is accessing the variable.

the function for health on 0 is death works just fine, because the client dies, and the server lives.

All of the variables work just fine, even the ones i invented for my code, but, they just wont function on the client.

Is it because I cannot do it in this manner, or is there some other intricacy that i am not understanding here?

Honestly thats where Im stuck.

Hopefully this helps better.

As far as replication goes that’s a totally different thing I can’t elaborate on without looking a lot further than what we see here.

You also need to cast in the beginning of the Init Set Base to your game instance like in the examples I provided to get the variables from the game instance.

I really do appreciate all the effort of the graphics.

They actually are functionally connected in the way I have it setup. If you don’t believe me try it yourself. Anyways. Thank you for your time.