I have a prefab in my project list (so not “active”, not in the hierarchy) and I want to instantiate it by script. So not by adding it to a variable in the inspector, but find the prefab by its name or tag or layer and instantiate it.
Still not clear I’m afraid…all prefabs are gameobjects. All you have to do is drag the prefab onto the slot in the script. Whether it’s in the hierarchy or not is irrelevant…in fact, I’m not sure under what circumstances you’d want to instantiate an object from the hierarchy.
There is no slot because the script is not a component of an object. it’s just a js file alone, this js file is called by another script and in this independant js file, I need to access a prefab.
Example:
this js file is linked to my character
var indeJS : IndependantJS;
if(Input.GetButtonDown("Fire1"))
{
indeJS.dosomething();
}
and this is the independant js file:
var target : gameobject;
static function dosomething(){
Instantiate(target, someVector3Data, someRotationData);
}
So if the script was a component of a gameobject I can drag and drop the gameobject, but not if the script is independant
Is it more clear?
Now maybe it’s not a good idea to do like that, but I just wanted to know if it was possible
Well, to clarify, the asset will be part of the game data and thus make the file size of the game bigger. I did not mean that the asset will be visible in your scenes if you don’t instantiate it.