A
A
AndrDev2020-03-06 20:08:06
Unity
AndrDev, 2020-03-06 20:08:06

What's the best way to load prefabs in Unity?

I need to load different prefabs in the scene depending on randomness and save. Google turned out only Resources.Load, but came across hints that it is better not to use it. And if you still use it, then in what place and will the scene loading process be correctly displayed then?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kit Scribe, 2020-03-06
@AndrDev

There are no problems using Resources.Load. Unless you need to put the resources used in the Resources folder, as far as I remember.
Load whatever you need before loading the scene and use the resulting resources however you like.

Pseudocode
void Awake(){
    var MyObj = Resources.Load("Prefabs/MyPrefab.prefab");
    Instantiate(myObj, Vector3.zero);
}


PS
The code may not be accurate, I have not been working with Unity for a long time

G
Griboks, 2020-03-06
@Griboks

I recommend using Instantiate. This is much better than working with dynamic resources.
Next, I suggest using bundles.
Well, loading resources directly is already an extreme method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question