Variable changing by itself

I’m making a game with a simultaneous turn system. I use an enum to store which player moves next which contains 3 options: player 1, player 2 and executing (for when theyve both moved and the game is resolving their actions).
The variable is only changed in one function, which has no loops/recursivity and only changes the variable once per call.

However, for some reason whenever it’s the second player’s turn the value of the variable keeps switching between player 1 and player 2 at a very high speed (faster than the actor’s tick). Using an aux variable or rep-notify somehow doesn’t show any changes, but printing the variable to the screen on tick does and you can see the diffrence in gameplay.
image

I’m absolutely desperate to fix this because i’ve never heard of unreal hallucinating like this, we have a deadline tomorrow and the only reason i found this is a bug that doesn’t even show itself if you start in the main level, only if you open it through a node (i think it’s something to do with the timing of the switching but i don’t really know).

Where is this code?

The only code that changes the variable is in a singleton actor. It’s a function that handles moving to the next turn/turn phase

1 Like

And there’s only one copy of this actor?

Yeah

1 Like

Sorry, had to check :joy:

But, variables don’t change by themselves, as we know.

What else can you tell me?

That’s what i thought as well, it’s really weird considering i used ctrl-F and nothing showed up outside of that function. I don’t really know what else could be causing it so at best i can give you screenshots of the code. Relatively recently i deleted the saved folder but that’s safe as far as i know. I’m going to go through everything again and if i don’t find any leads i think i’ll try replacing the variable or redoing the affected code.

Update: i’ve made a brand new variable that is just a bool that keeps track of wether it’s the second player’s turn to try to use it as a workaround since only the second player has this issue and it exhibits the same kinda behaivor, it switches from false to true nonstop when you set it to true. I’ve also tried using a set to count between how many values it switches and using that to know wether it’s the second player’s turn but saving the value of the variable doesn’t seem to work.

1 Like

I’m assuming it’s not actually multiplayer?

Does the count of actors in the level remain static while this is going on?

Are you staying on the same level?

Your Active Player var is a RepNotify. It should ONLY be set by the server.

The ONRep_Active Player function gets executed by Both Server and Clients when the variable value is changed.

If your On Rep is only supposed to execute logic for clients or server you need to add conditions at the start of the function.

We need to see more flow logic and functionality to accurately troubleshoot.

1 Like

Sorry for the confusion, this is a single-player game, i’m using repnotify to print something when the variable is changed. Which part of logic should i post? The variable is only called to be changed in one function, i could post the parts of the code that call that function but i already know the variable is changing without that function being called so i don’t think it would be of much help.
I’m 100% confident this is something wrong with unreal and not with my code because of it changing without the function being called and a brand new variable in the same actor doing the same thing.

Yeah it’s not multiplayer. Initially when i posted this i had a menu level and a main level and the bug would still happen if you started in the main level but only affected gameplay if you started on the menu level. I tried putting everything in the main level and it made it work in the editor but not in a build.
There are a few actors spawned at beginplay but none that can change this variable

1 Like