Solution to not spawning at spawnpoint

Solution for me was to delay the destruction of the portal. This simple function did the trick:

    private IEnumerator WaitBeforeDestroy(float wait)
    {
        
        yield return new WaitForSeconds(wait);
        Destroy(gameObject);

    }

On second thought: Just adding Destroy(gameobject,2f) would probably do the same.
The problem seemed to be that the portal was destroyed before the character position was properly updated, so delaying the destruction seems to do the trick.

6 Likes

Awesome solution!

I was getting the same result, but only when going one way; the location updated properly when going the other direction. Your solution worked for me, too. I suspect that it has to do with the number of objects to load in the scene; the way that worked was a very empty scene, where the one that didn’t had a lot of objects in it.

Can you get this added to the lecture? I was not able to progress until I found this community content since my portals weren’t working.

Just had the same issue. This definitely needs added to the lecture.

This fix is actually masking a bug. As written, the course code does not have an issue with resetting the character’s position.
Paste in your Portal.cs and we’ll take a look.

Privacy & Terms