Adding the DoNotDestroy when dealing with multiple Character Prefabs

This was my original Question on Discord
dreglin

Quick question, anyone happen to know if adding multiple player prefabs into the “core” game object will break it? Long story short, I have player 6 prefabs. When I use the default “player” prefab all is good, when I add in any additional prefabs something breaks. So, back to my original question… also, how would I go about fixing this issue?

More description of the issue:

My issue right now is with character selection. Start Menu -> Character Selection -> Game. Due to the way the RPG course was set up, there is no explanation of how to go about this.

I have the character selection working and it will load the correct character the player chooses, but it doesn’t work with the RPG course setup. I’ve tried multiple things to see if it will, but to this point have not gotten anything to work. I’m open to suggestions.

Hi diggerplus,

Just letting you know, I see this, and I will give you my ideas on how best to do this, but unfortunately due to personal matters, I’ll need to tackle this tomorrow.

Sorry about the delay getting back to this.

So you’re looking for a setup where the player can choose between a variety of characters to play. There are a few approaches you can take to this. I think the easiest approach is to not include the model at all in the Player Prefab. Here’s the thinking:

Set the Player up with all of the components just like you would on the regular player. This includes things like the DamageTaxtSpawner. Leave off the Model mesh, and skeleton.

Create a prefab for each character that you would like the player to be able to choose. Additionally, create a ScriptableObject PlayerDefinition. This ScriptableObject shoud contain a Prefab field that points to the correct character. Like the Inventory Items, this SO should be in a Resources folder so that you can ensure that the character is package in a built game.

For the Character Selection, once the character has been selected and the game is about to start, have a helper object that you will DontDestroyOnLoad (much like the Portal setup). This object will load the first scene and tell the Player to load the correct character, passing the ScriptableObject with the character definition.

The Player will then instantiate the prefab referenced in the ScriptableObject, setting itself as the parent. When you Save and Load a game, Capture the name of the ScriptableObject, and of course restore the same. This will be like the Weapon was Saved/Loaded in the first course.

There are a few more housekeeping details to take care of, the most notable being the Right and Left hand transforms. For this, I would have a class on the prefab to house these references. When the prefab is instantiated, notify Fighter and Fighter will get the references from this class and then Equip the Weapon. (Even if Fighter Restores/equips before this has happened, the notification that the prefab has loaded will just have Fighter re-equipping, which will allow the weapon prefab to be instantiated.)

Any variables that aren’t pointer based (perhaps adjustments to stats, etc) can be handled in the CharacterConfiguration Scriptable Object.

Sorry, wife threw a curve ball my way. Were moving. Will get back to this in a bit. Thanks.

This topic was automatically closed after 23 hours. New replies are no longer allowed.

Privacy & Terms