#Prefabs and scriptableobjects

1 messages · Page 1 of 1 (latest)

autumn drift
#

So, is it a prefab with a scriptableobject attached?

#

Or what do you mean exactly?

frozen narwhal
#

i got a scriptableobject with a

#

public GameObject go;

autumn drift
#

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

frozen narwhal
#

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

autumn drift
#

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

frozen narwhal
#

thats not the problem

#

when i do SO.go can i make multiply those ?

autumn drift
#

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)
frozen narwhal
#

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

autumn drift
#

What do you mean by "on a cube", on a script attached to the cube?

frozen narwhal
#

yes

autumn drift
#

Ok, but the scriptableobject doesn't know that

#

Only the cube knows that a scriptableobject was attached

frozen narwhal
#

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

autumn drift
#

and then you want a reference to each cube?

frozen narwhal
#

no

#

i get from each the scriptable object

autumn drift
#

ok

#

i think i get you

frozen narwhal
#

do i have then 10 different gameobjects

#

like do i have then 10 axes

autumn drift
#

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

frozen narwhal
#

oh so i have to instantiate those prefabs then

autumn drift
#

Yeah, if you want them in the scene at all

frozen narwhal
#

yes

#

i want the 10 axes then as 10 different objects

#

the axes are the gameobjects

autumn drift
#

yeah, I would store a reference to that cubes axe in the cube script

#

As you probably know, Instantiate() returns the new gameobject

frozen narwhal
#

so instantiate( scriptable.go ) would give me then a completely independent axe in the scene

autumn drift
#

yes

frozen narwhal
#

good

autumn drift
#

nice

#

sorry for my not-understandingness

#

I'm not a native english speaker as you can probably tell 😣

frozen narwhal
#

its ok

#

thanks

autumn drift
#

no problemo

#

ima archive this thread now

#

bye bye