Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: KillerCreeper on June 26, 2019, 09:25:43 PM

Title: Find Object By Name In Assets Folder
Post by: KillerCreeper 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.
Title: Re: Find Object By Name In Assets Folder
Post by: Thore 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.
Title: Re: Find Object By Name In Assets Folder
Post by: KillerCreeper 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.