I have a main player script, there is an On Start node that will trigger a Transform Set Position, setting the players position to the Player Position application variable (Vec3).
This worked for a while, up until just now. Nothing in the player script was changed, nothing that affects the Player Position application variable is changed, and when I inspect the Player Position variable it is being set correctly. The player is being set to the scenes default object position.
I have switched the On Start to an On Enable several times back and forth and nothing seems to work. Using an Update function to check whether or not the variable is in fact being set right shows me that it is, as the player is being set in the correct position.
I’m wondering if maybe there is something that automatically overwrites the objects position to the scenes default object position and its being triggered after the On Start and On Enable functions. I didn’t have an issue with this until today.
I’ve googled this issue and tried just about everything I could find to try and solve this. Any help is greatly appreciated.
Yes, I’ve tried several times and even waited overnight to see if it was just one of those days. Unfortunately it seems this issue is deeper than that.
Prior to the issue I was working on a door script and I was starting to test it out. When I entered one room I got curious and tried to enter the prior room and that’s when the issue started to come up.
That at least sounds like a starting point, what exactly does this door script do? Does it affect player position? Maybe revert that change or remove the door for testing. No idea what or why it would maintain some effect after stopping and reloading though.
The door function is what changes the Player Position variable.
When you interact with the door, theres a transition effect and the object referenced in the doors Transition Target variable has its position saved into the Player Position variable.
I’ve gone through several times and can confirm that this part is working (looking at the application variable and looking at the referenced objects position, both match perfectly). The only part not working is the player, on start/on enable, is not setting its position according to the variable.
The only change to the door script is replacing the raycasting part with a macro that does it (nothing in that macro references the players position, and it only exists for future objects that need raycasting so I dont have to redo the script).
Ahhh, okay, that makes more sense. You say the variable is being set correctly, but then the player is being moved to another position altogether. Is the Player Position variable attached to the player object or something else? Can you post pictures of the graph?
and the player position variable is an application variable. All of this used to work prior, and I have an old build from months ago that doesn’t have this issue.
Wow, yeah, that’s pretty straightforward, there’s not a whole lot of room for something to break, lol. Although, I’m not seeing where you’re setting the PlayerPosition variable, is that in the flow after the animator plays or part of the actual animation? Are you loading a new scene anywhere in this process?
Some things that you probably already know but I feel need to be said for others’ benefit. On Start will only ever trigger once, on the frame when a script is enabled just before any of the Update methods are called the first time regardless of whether or not the script is enabled. On Enable can run any number of times, but only whenever an object becomes enabled and active.
Obviously, you probably already know the above, since you’re been testing with both On Start and On Enable. One thing you can also test with is maybe adding a UI button really quick that’ll call a Custom Event that flows into your Set Position for the Player. That way you can just push a button to see what happens anytime, instead of checking the whole thing at once. You could always add buttons that mimic the different pieces of the process.
Just tried that with an On Keyboard Input and found something interesting.
When I press space, the player is set to the variables position, but very quickly snaps back to its previous position.
I have a Character Controller attached to the player, maybe that has something to do with it? Prior to about a month ago I was using rigid body on the player, but switched to Character Controller when I started implementing stairs, and the old build I tested was compiled before I had switched to the Character Controller.
Wow, okay, sounds like it was working all along except not. Must be something in the way the character controller works that sets position every update or something.
Figuring out that it was the character controller causing issues, I was able to google about the issue involving the character controller jumping back to a previous position and was able to find a solution