#would it be possible for you to show the

1 messages · Page 1 of 1 (latest)

hot umbra
#

Unfortunately, it's for work so I can't share the code itself.

sharp harness
#

understandable

hot umbra
#

I suppose I can try and give more info.

sharp harness
#

You could also check that the player object is not being affected by any physics or other forces when transitioning between scenes, as this could potentially cause it to move unexpectedly

hot umbra
#

When we transition to the new scene, we load in the map data and spawn the spawn points. Once those spawn points are spawned, we set the position to the first one we find.
I can confirm that the value is valid and that the position is getting set (for the next line in debugger) but it will snap me back by next frame.

From what I can tell, it doesn't ALWAYS do this, but it's relatively often. Could it just be a timing issue?

sharp harness
#

it could be a timing issue, cuz of loading assets and initializing objects, maybe the pos is being overwritten by another process

#

maybe adding a coroutine to delay setting the position of the player until after the scene has fully loaded and all initialization processes are complete

#

would fix it

#

im assuming when transitioning there is like a loading screen of some sort

hot umbra
#

We move from the other scene at 0,0,100
I'm setting it in two places.
OnLoadComplete (the spawn point isn't actually there yet so this just sets us to 0,0,0)
and in a custom OnMapLoaded, which happens about a half second or so after we can see. where it actually finds the spawn point at (0,1,0 let's say) and is supposed to move us there

sharp harness
#

yeah its 90% likely that its a timing issue

#

can you try a coroutine

#

that waits like .1 second

#

before trying to set the position

hot umbra
#

Sure, one sec

#

Looks like no dice from initial testing.

#

The onMapLoaded event happens probably half a second or so after we load the scene.

#

I threw a printout of the position into the logs for fun. It never changes (except for gravity) from 0,0,100

sharp harness
#

did you try setting the player's position directly in the Start() function instead of using the OnMapLoaded event to see if it makes a difference?

hot umbra
#

That... worked.

#

And then it didn't on trying it again

#

hmm, actually. it worked briefly

#

For a single frame

sharp harness
#

a possibility is that there is a race condition happening, where the player object is being moved to the correct position but then immediately moved back by another system or script you could try adding some debug logs or breakpoints to see exactly when and where the player's position is being changed

#

it may be that we're overthinking the shit out of this too Lol

hot umbra
#

Good point.

So Start, we move to 0,1,0
Update says that next frame we are at 0,0,0
Frame following we are back to 0,0,100
0.1 seconds after the OnLoadComplete event, we set to 0,0,0
The next Update log says we never changed
Likewise for the custom map loaded event

sharp harness
#

can you try a basic script that only sets the player's position and see if the issue still occurs?

hot umbra
#

Should that be on the player prefab or can it just be in the scene?

sharp harness
#

if u have one player object in the game then u can attach it to the prefab

hot umbra
#

Any specific timing?

#

I just tossed it on a button.

#

Similar thing. It moves for exactly one frame

sharp harness
#

hm

#

update woudlnt work

#

or lateupdate

#

maybe lateupdate

#

after update is called

#

or rather finished executing

#

but then itd be updated every frame

hot umbra
#

So... I'm just a dumbass

sharp harness
#

oh god

hot umbra
#

Let me confirm

#

I examined that player prefab my coworker made.
It has a character controller on it.

If I call Move, we move fine.
If I set position directly, we snap back.

#

Which... I'm realizing is still kinda weird. Can you not just set the position of something if it has a character controller?

#

Thank you @sharp harness for all your help. Sorry I overlooked something so simple lol.

I just disable the CC, move the guy, then re-enable the CC. Dunno if there's a better way than that, but this works

sharp harness
#

no worries am glad u got it to work