RPG Character Creator & Modular Armor Tutorial

Even with the mispelling, if you set the kneecap GameObjects (the objects under the category) to inactive, they’ll stay that way unless you activate them.

Where can I find this in the ‘SyntyStatics.cs’ script though…? There’s no definition for that in the database, and the spellings seem to match

Edit: The debug that was responding was this one, from ‘BuildCharacterGameObjectFromCatalogue()’:

if (t)
                {
                    for (int i = 0; i < t.childCount; i++)
                    {
                        Transform tr = t.GetChild(i);
                        if (tr == t) continue;
                        {
                            list.Add(tr.gameObject);
                            tr.gameObject.SetActive(false);
                        }
                    }

                    characterGameObjects[category] = list;
                }
                else
                {
                    // The debug that gave out a response:
                    Debug.Log($"BuildFromCatalogue - {name} - has no {category} category!");
                }

Edit: It took some time, but eventually I noticed in the hierarchy that ‘Attachment’ was spelled as’ AttachEment’… (The capital E was the silly mistake). It works beautifully now though :slight_smile:

Scroll up to the top of the post…

1 Like

Yup, fixed that (it was a spelling mistake from Synty), but my “Pickup Issue” still persists. I did some debugging, and I just found the root of the issue:

Somehow, saving my ‘Character Generator’ scene is responsible for my pickups not showing on the ground in my main game scene (which means it’s a saving transition problem). I eliminated the load line in my ‘CharacterGenToGame.LoadMainGameScene()’ script block, and it fixed the issue, but now my character is not being saved. So right now it’s either my character generator saves and loads my character, or my game has pickups that actually show up as expected. How do I go around this? (I haven’t tried placing Pickups in multiple scenes in a while, so I was unaware that this issue even exists)

I’ll go try fix this and the shield issue :slight_smile: (I’ll probably also get this problem off this thread since it probably has nothing to do with modular armors)

So it sounds like either the character isn’t getting saved properly, or it isn’t getting restored properly causing an error…
Are you using the BinaryFormatter or the Json saving? Either way paste in both your Capture and Restore methods and we’ll take a look.

It was something entirely different. I went to “PickupSpawner.cs”, and found this in the “RestoreFromJToken()” function (turns out I’m using the JSON, xD):

public void RestoreFromJToken(JToken state) {

            bool shouldBeCollected = state.ToObject<bool>();

            // The commented part below is what was responsible for the restoring issue:

            /* if (shouldBeCollected && !isCollected()) {

                DestroyPickup();

            } */

           // Beyond here should be fine lah (Malaysian accent kicked in)

            if (!shouldBeCollected && isCollected()) {

                SpawnPickup();

            }

        }

From my understanding, that part says “If this item should be taken but it wasn’t, then destroy it immediately when the game scene starts” (which doesn’t make sense tbh… the player needs his chance, right?)

And the character wasn’t properly saved either tbh, since his “Body Art” color wasn’t properly restored. There are missing parts for that which I will probably fill on my own (this one was an extremely easy fix)

If that’s not it, then here is my “CharacterGenerator.cs” saving system (although I’m not sure if this is relevant or not):

public JToken CaptureAsJToken()
        {
            return JToken.FromObject(new ModularData(isMale, hair, facialHair, head, ears, eyebrow, skinColor, hairColor, bodyArtColor, eyeColor));
        }

        public void RestoreFromJToken(JToken state)
        {
            equipment.equipmentUpdated -= LoadArmor; //prevent issues
            ModularData data = state.ToObject<ModularData>();
            gender = data.isMale ? SyntyStatics.Gender.Male : SyntyStatics.Gender.Female;
            hair = data.hair;
            facialHair = data.facialHair;
            head = data.head;
            eyebrow = data.eyebrow;
            skinColor = data.skinColor;
            hairColor = data.hairColor;
            SetHairColor(hairColor);
            SetSkinColor(skinColor);
            equipment.equipmentUpdated += LoadArmor;
            Invoke(nameof(LoadArmor), .1f);
        }

The logic of this code:

            if (shouldBeCollected && !isCollected()) {
                DestroyPickup();
            } 

is meant to deal with travelling between scenes back and forth… So if you pick up the item, then transit to another scene and then head back into the old scene, this code says “Hey, the player already picked this up, so we don’t spawn it”.

That being said, it makes no sense that this would even be called when going from the Character generation scene (which should be on a new player) into the scene, since those pickups shouldn’t be in the Character Creation screen and hence, their status should not be saved.

Can you please elaborate more on this? How do you place a Game Scene on the player? I’m probably a little rusty on this one (if commenting out that part isn’t the solution, then what is?)

I mean on a new player, as in the only thing that should be saved in the Character Generation scene should be a player.

Well, I did go through all my individual components of the scene, and only the player has a JSON Saveable Entity on him, and there are no pickups in that game scene, but the problem still persists (I put the commented code back into the game)… Any alternatives?

Are you starting from a clean save file in the Character Generation scene?

Yup, I’m starting from a brand new file that I created in my game main menu, and the problem is going through all 3 scenes (for now they’re 3)

And does your game main menu have any IJsonSaveables in it?

Nope, none

OK so I did a little more debugging, and I learned that the save file names which I used before do collide with the new ones of the same name (in other words, if I try creating a new save file with the same name as an old one, the game allows it through, but it will use the old one, so there’s a bad collision there), so I think the solution for this is to create a Save File name function that blocks us from naming the same save files more than once. How can we do this?

If only there was a way to get a list of save file names…

Psuedocode:

if(saveFileNames.IndexOf(saveFile)>=0) return;

Do we place this in ‘MainMenuUI.NewGame()’? before this line?:

savingWrapper.value.NewGame(newGameNameField.text);

Yes, once you determine that the save file is not in the list of save names.

OK well, this is what my “MainMenuUI.NewGame()” function looks like, after fixing it to consider for the issue:

        public void NewGame() {

            string filePath = Path.Combine(Application.persistentDataPath, newGameNameField.ToString());
            if (File.Exists(filePath)) return;

            // Load the named new Game:
            else savingWrapper.value.NewGame(newGameNameField.text);
        }

But it still didn’t work…

Doesn’t factor in the extension

If only there was a method in SavingSystem that gave you all of the Save files…
Like the one that lets you create the buttons…

Try this:

public void NewGame()
{
    string newGameName = newGameNameField.text; //multiple access to properties is inefficient
    if(savingWrapper.value.ListSaves().ToList().IndexOf(newGameName>=0) return;
    savingWrapper.value.NewGame(newGameName);
}

Privacy & Terms