I have a bit of code that I want to reuse. All it needs is to switch prefabs in the code, and it’s all set to go.
Problem is, I can pass two different prefab variables through the Inspector to the public variables, but can’t get the prefab variables into Instantiate().
The only way I know of a workaround that is key to instantiating different prefabs with reusable codes dynamically is somehow to use Resource.Load(), and pass it in different filename (file paths) strings. I currently can’t confirm if there are other ways, such as passing it through Inspector, having Resource.Load() actually load the passed prefab parameters into Instantiate() and dynamically instantiate prefabs that way.
Is the method I mentioned above the only way of doing this? Any other alternatives I haven’t known of?
Not sure I understand your question… if you are looking to instantiate things from a “prefab” field that you set in the editor, then simply dragging it into the public field in the editor and then passing that value to Instantiate() should work.
Resources.Load() is only for pulling stuff off the asset storage area of the app, but in order for it to be found, it must live under a folder called Resources.
Am I helping your question at all here? I’m not sure that I am…
I wanted to pass in different prefabs into the Inspector, and have them be instantiated through code, but Unity says Instantiate() requires prefab object as parameters, even when the parameters are prefabs passed in through the Inspector.