Question Solved: How To Code RestoreAllFromStore1 (Material Presets)

CodeyChaos

New member
Messages
13
Reactions
2
Points
3
Does anyone know how to access the 3 save slots for clothing materials presets via code? The buttons in the green and red boxes at the top right of the materials tab in clothing customization. They're accessed from a trigger via
ReceiverAtom- Person
Receiver- [clothing item]Material[material name]
ReceiverTarget- RestoreAllFromStore1
I'm building a custom UI plugin and I'd like to script access to these slots into my own dropdown menus.
 
Got it.

Once you know the JSONStorable ID for the clothing item material you can call RestoreFromStore1
It'll be something like
CreatorName:ClothingItemNameMaterialCombined.RestorAllFromStore1();

If its a MeshedVR item it wont have a creator name.
Something like
TankTopMaterial.RestorAllFromStore1();

Here's a script to log all the JSONStorables currently active on the person atom named "Person", so you can find the ID of the item to modify
Code:
using System.Collections.Generic;

public class logStorables : MVRScript
{
    public override void Init()
    {
        // Find the 'Person' atom
        Atom personAtom = SuperController.singleton.GetAtomByUid("Person");

        // Get all storables associated with the 'Person' atom
        List<string> storables = personAtom.GetStorableIDs();

        foreach (string storable in storables)
        {
            SuperController.LogMessage("Storable ID: " + storable);
        }
    }
}

Once you find your clothing material in that log you can use it in the following demo
Code:
public class LoadMatPresetsDemo : MVRScript
{
    private Atom personAtom;
    private JSONStorable clothingItemStorable;

    public override void Init()
    {
        var loadButton1 = CreateButton("Load 1", true);
        loadButton1.button.onClick.AddListener(LoadPresets1);

        var loadButton2 = CreateButton("Load 2", true);
        loadButton2.button.onClick.AddListener(LoadPresets2);

        var loadButton3 = CreateButton("Load 3", true);
        loadButton3.button.onClick.AddListener(LoadPresets3);

        var loadButton4 = CreateButton("Load Default", true);
        loadButton4.button.onClick.AddListener(LoadDefault);

        var saveButton1 = CreateButton("Save 1");
        saveButton1.button.onClick.AddListener(SavePresets1);

        var saveButton2 = CreateButton("Save 2");
        saveButton2.button.onClick.AddListener(SavePresets2);

        var saveButton3 = CreateButton("Save 3");
        saveButton3.button.onClick.AddListener(SavePresets3);

        // Find the 'Person' atom
        Atom personAtom = SuperController.singleton.GetAtomByUid("Person");

        // Get the storable with ID "[creator:itemNameMaterialMaterialName]"
        clothingItemStorable = personAtom.GetStorableByID("[creator:itemNameMaterialMaterialName]");
    }

    private void LoadPresets1()
    {
        if (clothingItemStorable != null)
        {
            clothingItemStorable.RestoreFromStore1();
        }
        else
        {
            SuperController.LogMessage("not found");
        }
    }

    private void LoadPresets2()
    {
        if (clothingItemStorable != null)
        {
            clothingItemStorable.RestoreFromStore2();
        }
        else
        {
            SuperController.LogMessage("not found");
        }
    }

    private void LoadPresets3()
    {
        if (clothingItemStorable != null)
        {
            clothingItemStorable.RestoreFromStore3();
        }
        else
        {
            SuperController.LogMessage("not found");
        }
    }

    private void LoadDefault()
    {
        if (clothingItemStorable != null)
        {
            clothingItemStorable.RestoreAllFromDefaults();
        }
        else
        {
            SuperController.LogMessage("not found");
        }
    }

    private void SavePresets1()
    {
        if (clothingItemStorable != null)
        {
            clothingItemStorable.SaveToStore1();
        }
        else
        {
            SuperController.LogMessage("not found");
        }
    }

    private void SavePresets2()
    {
        if (clothingItemStorable != null)
        {
            clothingItemStorable.SaveToStore2();
        }
        else
        {
            SuperController.LogMessage("not found");
        }
    }

    private void SavePresets3()
    {
        if (clothingItemStorable != null)
        {
            clothingItemStorable.SaveToStore3();
        }
        else
        {
            SuperController.LogMessage("not found");
        }
    }
}
 
Last edited:
Upvote 0
Back
Top Bottom