2
\$\begingroup\$

This may seem like a dumb question, but I want a single player object for the entirety of my game. However when I load multiple levels obviously I need to reload the player so I would create a player prefab and instantiate him. However, it seems counterintuitive as prefabs are for objects you want to create multiple instances of easily, correct? Also, I need values to be carried over accross levels for my player object therefore I guess I would need a static global singleton to store the player objects.

Hence the dilemna and confusion! Can anyone help me out here?

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

Games really aren't about "supposed to" - they're about what works and what doesn't.

If creating a player prefab makes it easier for you to spawn the player avatar in any scene you need them in, and that works for your needs, then it's a good solution.

No Unity police will knock on your door and say "I heard you used a prefab for an object that's only spawned once. That'll be a bajillion dollar fine" - the tools exist for you to get your work done, so use them the way that makes sense to you.

Also, I need values to be carried over accross levels for my player object therefore I guess I would need a static global singleton to store the player objects.

Not necessarily. You could also use DontDestroyOnLoad or additive scene loading to persist one instance of an object throughout your game, rather than unloading & respawning it every time you change to a new level.

\$\endgroup\$
2
  • \$\begingroup\$ Good answer! But still would be nice to hear what is most common or recommended to closer follow to the standards \$\endgroup\$
    – Dirk Boer
    Commented Apr 15, 2018 at 9:04
  • \$\begingroup\$ "If creating a player prefab makes it easier for you to spawn the player avatar in any scene you need them in, and that works for your needs, then it's a good solution." — That's about as close to a standard as you're going to find: use Prefabs where they help. \$\endgroup\$
    – DMGregory
    Commented Apr 15, 2018 at 11:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .