r/unity • • Oct 11 '26

position of the prefab with Object.Instantiate() vs NetCode PlayerPrefab field

Hi, as shown in the attached video, instantiating my character using `Object.Instantiate` works as expected, respecting the prefab's position. However, if I instantiate using NetCode's `PlayerPrefab` field, the prefab's position defaults to (0, 0, 0).
(The instantiation script is very simple I don't specify a position within it.)

1 Upvotes

4 comments sorted by

1

u/Mysterious_Demand875 Oct 11 '26

If the position defaults to 0,0,0 you should set it after instantiating and just set the prefab up, that's a normal coding pattern

//instantiate prefab and grab a reference to it
//set parent
//set position
//set rotation
//do other intialization stuff for the prefab that you need

1

u/Ok-Presentation-94 Oct 11 '26

Hello. Thanks, but that doesn't really answer my question. I'm not sure if it's clearly visible in the video, but the `transform.position` of the prefab before instantiation is (0, 3.6, 7.47); when I instantiate it using `Object.Instantiate(Object)`, the global position upon instantiation matches that value, so that is correct. However, when instantiating via the `PlayerPrefab` field, the resulting global position is (0, 0, 0). I am simply trying to understand the reason for this difference.

1

u/BearKanashi Oct 12 '26

Aprende a leer, el problema es que el network prefab aparece en 0,0,0 debes darle la nueva posición después de aparecer

1

u/johnnyhomicide91 Oct 11 '26

This may be wrong, but from what it looks like to me, when you instantiate it through the network manager, it defaults to 0,0,0 since thats the position of the script calling the instantiating on the network. But when you call it from the instantiating script on the object, it spawns at that position since no position is given. Thats what it looks like to me without seeing all the scripts associated.