Playmaker Forum

PlayMaker News => General Discussion => Topic started by: Handrews on December 02, 2020, 06:45:39 PM

Title: Get Prefab by name and store it into GameObject Global Variable
Post by: Handrews on December 02, 2020, 06:45:39 PM
Basically I need a way to find a Prefab on my Assets folder using his name and then store it into GameObject variable to use it on Create Object...

Title: Re: Get Prefab by name and store it into GameObject Global Variable
Post by: Fat Pug Studio on December 03, 2020, 03:31:14 AM
Use Resources Load with asset path, then store it as you like.
Title: Re: Get Prefab by name and store it into GameObject Global Variable
Post by: Handrews on December 03, 2020, 05:38:26 AM
Yea but i need a way to find the prefab by name too
Title: Re: Get Prefab by name and store it into GameObject Global Variable
Post by: Handrews on December 03, 2020, 05:55:04 AM
Ok i made it using Build String to create a path using the name stored in the variable...but now "Resources Load" seems to not be working or not recognizing the path (Assets/FireBolt1.prefab) and i don't know why...
Title: Re: Get Prefab by name and store it into GameObject Global Variable
Post by: djaydino on December 03, 2020, 08:27:37 AM
Hi.
You need to place the things you want to load into a 'Resources' folder.

https://docs.unity3d.com/ScriptReference/Resources.Load.html

So for example if you have your fire bolt in a folder like this :

Assets/Some folder/Some subfolder/Resources/Bolts/FireBolt1.prefab

Then you would load it with "Bolts/FireBolt"
Title: Re: Get Prefab by name and store it into GameObject Global Variable
Post by: Handrews on December 03, 2020, 09:15:02 AM
Nice! It works" Thx u very much!  :)