Selected object into next scene?

Alright. So I have two scenes:

  • Main Menu
  • Game

In the Main Menu I have a character select screen where I can pick the character I want to use. That part works just fine. I select the GameObject and an animation plays on the selected Object. When I’ve selected the character I want, I’ll press “Play” which loads the Game scene.

But I just can’t get that specific character to be shown in the next scene. I’ve already placed all the characters on top of each other, and want to destroy all the ones that was “not selected”. I’ve tried making the SelectedCharacter GameObject Static, but with no luck. I just can’t wrap my head around on how to make this work.

Any tips, ideas or whatever on what I should do? I’m completely stuck.

Have you tried:

If you do:

DontDestroyOnLoad(rootGameObject);

Loading a new scene won’t destroy the root game objects and all its child game objects and components.

Can use a persistent “data” object to remember which char you want, then reference that in the next scene. For example (on an empty): class charStats { public int charNum; public int gold; ... }

Then in your menu script somewhere would have things like: GameObject.Find("CharData").GetComponent().charNum==2;

In your game scenes, each character could then check to see if it had the correct charNum: if(GO.Find("CharData")....charNum != myCharNum) Destroy(me)

The CharData gameObject with the script would be the only persistant (dontDestroyOnLoad.)

Alternative is to have the character be persistent. The (minor) problem there is you need to mark the starting spot for each scene and “teleport” the character there on scene load (since the new scene probably won’t start at the exact xyz the last one ended.)

Alright, so I actually figured it out on my own. I somewhat did what Owen Reynolds said, but I used PlayerPrefs instead. Works like a charm and does exactly what I want. Can’t believe I didn’t know about it before. So much hassle for something so super simple.

Thanks for helping out guys!

Please add full script Thanks you :smiley: