#Prefabs and scriptableobjects
1 messages · Page 1 of 1 (latest)
So, is it a prefab with a scriptableobject attached?
Or what do you mean exactly?
if you instantiate a prefab, you will create a clone
the clone isn't even aware of the scriptableobject, only the object that created it
like i wanted to hold my axe and sword and so on in a scriptable object and then "get that scriptable and get a prefab from it"
so i can have multiple swords and multiple axes
public GameObject go; if this is your prefab, just go: THESCRIPTABLEOBJECT.go
then you get the prefab
but obviously you first have to get a reference to that SO
When you script an SO, you're only making the base class, then, using the inspector you can add instances of that base class. When you do SO.go, you're getting the prefab from that specific instance of the base scriptableobject class.
[SerializeField] Weapon weapon; // Weapon is a scriptableobject base class
Instantiate(weapon.go); // Instantiate the prefab on the weapon (an instance of the base SO)
when i put then the scriptable object on a cube, and have multiple cubes
and get all go objects from them
are those different
or same object
What do you mean by "on a cube", on a script attached to the cube?
yes
Ok, but the scriptableobject doesn't know that
Only the cube knows that a scriptableobject was attached
i got like 10 cubes with on each a monobehaviour, which has the scriptable object in it
and from each i call the getter for the prefab
and then you want a reference to each cube?
no, if you are just getting it, you're getting the same prefab on all of them
But if you are instantiating that prefab, you're gonna create different objects
oh so i have to instantiate those prefabs then
Yeah, if you want them in the scene at all
yes
i want the 10 axes then as 10 different objects
the axes are the gameobjects
yeah, I would store a reference to that cubes axe in the cube script
As you probably know, Instantiate() returns the new gameobject
so instantiate( scriptable.go ) would give me then a completely independent axe in the scene
yes
good