Why are these Materials and Actor Class Reference variables not changing when set?

I’m working on a character customization interface for my game. I was going to set up variables, in the player controller, for the head and body materials and the actor reference for the character’s hair, which were going to change based on what the player selects in the character customization screen. I noticed that it was not working, and I found that when I set the variables, the variables did not change to what I had set them to. They would simply stay at whatever the default value is. How can I get these variables to actually change?


The issue may come from the cast. You get the player controller and cast to a character class, the cast probably fails.

1 Like

I converted it to an impure cast and tested with print strings. The cast succeeds, so that is not the problem. Good idea though.

03


If I print string in my player controller, I get the value I set the variable to, but when I print string after entering a new level and casting to this same player controller, I get the default value. Anyone know why my player controller resets to default values when changing levels?

Variables are reset beetween levels. To pass a variable you need to store it somewhere before exiting the level, and get it back when entering next one. Game instance class is a good place to do it since it lives beetween levels, but I’m not sure concerning multiplayer (I have 0 knowledge about multi), maybe in that case there could be another class for that

1 Like

I agree with putting those variables in the game instance. It can be kind of tedious passing those variables over by setting this in the game instance, but it’s very reliable. Its like passing a heavy object over a fence and walking a ways around and pick it up without having to carry it all the way around…

First you can start by creating the variable in the game instance like this. Be sure to make them instance editable and expose on spawn.

SettingInstanceVarExample

I would then cast to the game instance from your widget buttons and set those variables like this.

From there I would I go into the character blueprint and create some custom events that execute the variables and nodes at runtime like this. *Note I have mine set up as multicast because mine is a multiplayer example. But calling the events is essentially the same.

After creating those custom events and execution logic you need to go into the player controller and call those events as the controller will always revert back to the defaults. Therefore they must be called on event begin play or executed perhaps through the game mode using the corresponding controller. I set up a series of branches to determine what is what and call the respecting events like this.

These will be called each time your controller resets and essentially as long as the game is in-play they will remain the same until you change them. You can even call them directly from the character blueprint, but that can only happen during runtime and maintain the variables. I’m not sure of any other way to effectively do this between level changes and come out the other end with the correct settings. Especially in a multiplayer environment. Maybe someone else can chime in…

Of course you can do this with any number or variables like floats, integers, booleans and such like you have in your screenshots…