playMaker

Author Topic: Find Object By Name In Assets Folder  (Read 914 times)

KillerCreeper

  • Playmaker Newbie
  • *
  • Posts: 44
Find Object By Name In Assets Folder
« on: June 26, 2019, 09:25:43 PM »
I am creating an item dropping system. When you drag and drop an item out of your inventory, it instantiates whatever object you have in front of the player. Each item has a string variable named "itemID". (I understand item ids are usually integers but I can always change that if strings ever become a problem in the future but that is beside the point.)

Is there any way to find a game object prefab in the assets folder with this itemID variable I have? Every item game object's name is their own itemID.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Find Object By Name In Assets Folder
« Reply #1 on: June 26, 2019, 09:42:37 PM »
You probably have a reason for using IDs, but it sounds bug-prone. You should indeed use integers, because strings are heavier on performance (according to a Unity workshop). 

It may be possible to use the Resources folder in the way you want, it‘s for loading dynamically as far as I know. Maybe you find a solution in this direction.

I would load the assets into an array, and use the array ID instead of hand-named IDs, to retrieve items. I would store the array in a scriptable object, which would also make it persist across scenes.

KillerCreeper

  • Playmaker Newbie
  • *
  • Posts: 44
Re: Find Object By Name In Assets Folder
« Reply #2 on: June 26, 2019, 10:48:17 PM »
Hey, thank you for the fast reply. Right after I made this post I actually changed the item ids back to integers. I've been debating whether I should or not since they used to be integers when I first created them. Later on, I changed them to strings, thinking it would be easier to use. At the time I didn't realize how heavy strings can be on performance.

Anyway, I tried what you said and it worked! So, thank you very much, I appreciate it.