how to instantiate saved objects back into game

hi!
I’m currently saving my prefabs into Assets/Resources/nameofprefab and I would like to load and instantiate them back into the game (I’m trying to make a very basic prefab load/save solution) I have been told to use Resources.Load, however, I have not been able to make it work - can anyone give me any advice on this problem?

thanks!

Hi @Goubermouche, let’s see if this helps you.
Two easy ways for this:

1.-You can easily have a reference to your prefab on any script with a GameObject variable public, then drag the prefab to that script in the inspector and then instantiate itwith something like this:


166645-prefabedit.png


    public GameObject targetPrefab;
    void Start()
    {
        Instantiate (targetPrefab);
    }

2.-If you want to load them into a variable and then instantiate, just do something like this:
Imagine your prefabs is under “Resources” folder, then under a folder called “Prefabs” and you called it “MyPrefab”. To load it into a variable, you can just do:

GameObject targetPrefab = Resources.Load<GameObject>("Prefabs/MyPrefab");

And then do the instantiate think like above.

Hope this helps.