Creating/Saving prefabs during runtime?

This questions regards events after a scene has started (after asset processing, start() or awake() functions).

Somewhat similar to saving a game state or player prefs, I'm looking for a way got save the state of a gameObject at some arbitrary time, having undergone arbitrary dynamic changes, and store it permanently.

For example, I'd maybe "grab gameObject A at Time=1000 seconds".

I'm asking specifically about prefabs, as I'd potentially like to include these in other scenes later on.

As far as I know, you can't do this at runtime. In fact, it's really hard to try and save anything at runtime (as that's not how Unity's designed to function).

You can, however, do it when the game isn't running (with an Editor script, that goes in the /Editor/ folder), like this:

Use EditorUtility.CreateEmptyPrefab to create an empty prefab object, and then once you have that reference (as well as the game object that you want to save into it), you can use EditorUtility.ReplacePrefab to "save" the game object inside the prefab you just made. Be sure to name your prefab something unique so it doesn't get overwritten.

While not specifically about saving prefabs, this question talks about saving the state of a game object during run time.

You can manually copy the gameobject you are editing at runtime, and paste it in the editor later. It is like creating a carbon copy. If it's easy to insert that cc back into your instance pool, then this should be useful to you. Be aware though that it will contain any runtime changes that you are doing, such as attaching scripts or changing names, etc.

There’s an asset store thing called ‘PlayMode persist’ I think. I use it, it works quite well.

found this script":
class CreatePrefabFromSelected
its awesome apart from the generated mesh isnt in ther on that version

For just creating new prefabs, you can drag your folder or whatever into the project section and it will create a prefab which you can then drag back onto your editor after runtime.

I would make all the data you want to save part of a scriptable object, then you just need to save and load that data and apply it… unless I’m misunderstanding something…