Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Referencing Player from main menu

Discussion in 'Scripting' started by S3Critsss, Jun 19, 2020.

  1. S3Critsss

    S3Critsss

    Joined:
    Jan 6, 2020
    Posts:
    111
    I need to get access to my player to be able to customize him from the main menu shop but i don't know how i can reference him because he is not in my scene but n the next one. Can anyone show me a way i can do this
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    10,003
    You either need to put it in the scene or you need to store the data somewhere and apply later when you jump into the game.

    How to transfer data between scenes:
     
  3. S3Critsss

    S3Critsss

    Joined:
    Jan 6, 2020
    Posts:
    111
    In This video he is saying bringing data to the next scene but i need to call the player from the next scene. (If that is not what the video is like. im sorry. but i didnt watch the whole vid)
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,970
    However you do it, whatever scripts or GameObjects are storing the customized values about your player, those values and that player has to be in the next scene too.

    You can do this any number of ways, such as:

    1. mark him as do not destroy and he'll stick around until you destroy him at end of game.

    2. serialize all the custom settings somewhere persistent (See above video), then "recreate" him in the player scene using those custom settings

    3. break the player out into a separate additively-loaded scene that never reloads after you customize him, but you unload other customizing UI and additively load the content scene (I don't recommend this; it gets fiddly)

    4. etc. etc. etc.