Skip to content

Instantly share code, notes, and snippets.

@CodeSmile-0000011110110111
Created February 22, 2023 15:47
Show Gist options
  • Save CodeSmile-0000011110110111/b41f9f51b3dfef5c24b8a5c4de624b0a to your computer and use it in GitHub Desktop.
Save CodeSmile-0000011110110111/b41f9f51b3dfef5c24b8a5c4de624b0a to your computer and use it in GitHub Desktop.
Fixing the "unsaved" random seed by changing the serializedObject's property and ApplyModifiedProperties
public override void OnInspectorGUI()
{
DrawDefaultInspector();
var script = (RandomMeshSelector)target;
if (GUILayout.Button("Change Random Seed"))
{
serializedObject.FindProperty("m_RandomSeed").intValue = script.GenerateNewRandomSeed();
serializedObject.ApplyModifiedProperties();
script.SetRandomMeshIndex();
script.SelectMesh();
}
}
@CodeSmile-0000011110110111
Copy link
Author

This method now needs to return the seed, or generate it in the editor script:
script.GenerateNewRandomSeed();

A slightly more involved solution is in the below repository. With that you can just pick one of the meshes rather than having to rely on the desired one to randomly pop up. It requires changing the MB script so that it persists a "current mesh index" rather than generating it 'randomly'.

https://github.com/CodeSmile-0000011110110111/CodeSmile-Twitch-Public/blob/main/HowToDoStuff/Assets/Scripts/Editor/RandomMeshSelectorEditor.cs

https://github.com/CodeSmile-0000011110110111/CodeSmile-Twitch-Public/blob/main/HowToDoStuff/Assets/Scripts/RandomMeshSelector.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment