#How to assign variables in game to a prefab in assets folder

49 messages · Page 1 of 1 (latest)

dull kestrel
#

what line is the error coming from

prime dragon
dull kestrel
# prime dragon here

okay , so you got 2 choices
first -> spawn the border and getting reference for the spawned perfab not the original prefab
Second -> making the border a child for the item and simply deactivate it or activate it

#

PSA: The "Unit" class is a simple class I created to represent a unit in my game. It's NOT an inbuilt class. Sorry for the confusion.

As a new dev, keeping references to game objects you need can be a little confusing. Learn how to store game objects for later use as well as allowing external scripts access to your goodies.

Instead of trying ...

▶ Play video

Check out the Course: https://bit.ly/3i7lLtH


Learn 5 different ways you can connect your gameobjects in Unity. Ranging from direct references & singletons to scriptableobjects and injection.

More Info: https://unity3d.college - (and where you can submit your own questions)

Join the group: http://unity3d.group

▶ Play video
#

and i suggest that you start by watching someone making a full inventory system instead of making your own , it will save you time and headache and you have some guidelines to follow

prime dragon
prime dragon
dull kestrel
#

thats why i suggested for you this videos , you will create one border , from my guessing its the border that appear on the item to show which item is currently selected , so simply u will create a SelectionBorder in Inventroy Canves and simply getting reference for it for example with tag and control its position

prime dragon
#

As you can see in the video there are 3 variables that the prefab need when it enter the game: the script "EquippableItemUI", the slotBorder and another game object that is the 3d version of him

#

i don't know how to reference them in the prefab non manually

dull kestrel
worldly falcon
dull kestrel
simple hamletBOT
#
Rule #10. English only

We are an English community around English content with English speaking moderation team. Everyone here understands English, other languages not so much.

prime dragon
#

(regarding the video i sent) : As you can see if an Item spawn in the scene it have all it need to work except for the equippableItemUI script that I have to assign manually. Do you know how can i do without using the Find?

#

If someone know a solution it is really appreciated BlobCute

spice temple
#

The error is pretty obvious

#

You can't edit the prefab during runtime

#
slotBorder.transform.SetParent(transform.parent);
slotBorder.transform.localPosition = new Vector3(0, 0, 0);
slotBorder.SetActive(true);

These 3 lines are attempting to edit the prefab

prime dragon
spice temple
#

because the variable is pointing to a prefab

prime dragon
prime dragon
# spice temple

As you can see the code works fine when the reference for the "EquippableItemUI" variable is the gameObject in the scene, but when this reference is the prefab from the assets folder then it doesn't works

#

One second i'll share the codes

#

the error was in the EquippableItemUI script

dull kestrel
#

you should consider any prefab as a Template or a Blueprint , its a thing that others inhert from

prime dragon
#

the player can't assign thr variable manually

dull kestrel
dull kestrel
prime dragon
dull kestrel
prime dragon
#

Thanks for the advices BlobCute

dull kestrel
prime dragon
worldly falcon
prime dragon
#

I'm really happy of that :))

#

It surely is an improvable script but i like that i did it alone

#

'll improve it when i will learn about instances, "this", get; set; and other things (if my script need these)

dull kestrel