Runner Spawns GameObjects at different location than provided

Options

When I spawn a prefab with the runner it spawns at a different location than requested. How can that be?

Requested location (-3.86, 9.03, 151.47) spawned position (-28.75425, 2.314931, 247.3364).



Best Answer

  • Luke_Sta
    Luke_Sta admin
    Answer ✓
    Options

    Since the  NetworkCharacterControllerPrototype uses a Unity CharacterController underneath it needs to follow some guidelines for moving a Unity CharacterController.

    First of all you should only move in FixedUpdateNetwork. For the movement itself modifying the transform directly is not supported by the character controller. Instead do:

    • For regular movement call the Move function on the NetworkCharacterControllerPrototype
    • For teleportation, firs disable the CharacterController component, update the transform, then enable the CharacterController again. (CharacterController means the Unity component not NetworkCharacterControllerPrototype)

Answers

  • Luke_Sta
    Options

    Hey,

    Could you provide us with some more information around the issue?

    • The Fusion version you are using.
    • The code which is spawning the prefab.
    • Setup of the prefab, are there any components that could influence its position (Rigidbody, CharacterController etc.)

    You might also want to try If the problem still happens if you replace your Prefab with an empty GameObject prefab.

  • Unavi
    Options

    Release 1.1.1 Stable

    Code which is spawning the prefab. GetRandomSpawnPoint() returns a tuple of a position and rotation of a spawn position marker in the world.

    Prefab:

    If I remove the MovePlayer Coroutine I spawn wrong. With it I get moved to the proper location 1 second after spawning. If I wait for 3 frames instead the character seems to get launched into the air.


    That is the final location of the character in the end. Nothing special about it that would explain what is happening.


  • Luke_Sta
    Options

    I see that you are using a CharacterController. Most likely this is what's causing the issue. I recommend to either use NetworkCharacterControllerPrototype as a simple replacement (not production ready) or have a look at our advanced KCC.

  • Unavi
    Options

    I am using NetworkCharacterControllerPrototype, just copy pasted it and changed it to have strafing, instead of rotating to the walk direction. It seems to be that spawning at a position can force the player into a random direction if it seemingly collides with something, but later moving the pawn to the same location works fine.

  • Unavi
    Options

    When I set the position of the player with networkPlayer.transform.position = xyz, it moves the player there but one frame later the player is moved back to the original location. How can I set the position of the Network Character Controller Prototype?

    I am using Shared Topology if that makes a difference.

  • Luke_Sta
    Luke_Sta admin
    Answer ✓
    Options

    Since the  NetworkCharacterControllerPrototype uses a Unity CharacterController underneath it needs to follow some guidelines for moving a Unity CharacterController.

    First of all you should only move in FixedUpdateNetwork. For the movement itself modifying the transform directly is not supported by the character controller. Instead do:

    • For regular movement call the Move function on the NetworkCharacterControllerPrototype
    • For teleportation, firs disable the CharacterController component, update the transform, then enable the CharacterController again. (CharacterController means the Unity component not NetworkCharacterControllerPrototype)
  • Unavi
    Options

    Nice that solved the problem.


    Thank you :)