playMaker

Author Topic: Get Prefab by name and store it into GameObject Global Variable  (Read 2358 times)

Handrews

  • Playmaker Newbie
  • *
  • Posts: 36
  • 3D Artist & Game Developer
    • Thetra Games Artstation
Get Prefab by name and store it into GameObject Global Variable
« 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...


Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Get Prefab by name and store it into GameObject Global Variable
« Reply #1 on: December 03, 2020, 03:31:14 AM »
Use Resources Load with asset path, then store it as you like.
Available for Playmaker work

Handrews

  • Playmaker Newbie
  • *
  • Posts: 36
  • 3D Artist & Game Developer
    • Thetra Games Artstation
Re: Get Prefab by name and store it into GameObject Global Variable
« Reply #2 on: December 03, 2020, 05:38:26 AM »
Yea but i need a way to find the prefab by name too

Handrews

  • Playmaker Newbie
  • *
  • Posts: 36
  • 3D Artist & Game Developer
    • Thetra Games Artstation
Re: Get Prefab by name and store it into GameObject Global Variable
« Reply #3 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...

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Get Prefab by name and store it into GameObject Global Variable
« Reply #4 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"

Handrews

  • Playmaker Newbie
  • *
  • Posts: 36
  • 3D Artist & Game Developer
    • Thetra Games Artstation
Re: Get Prefab by name and store it into GameObject Global Variable
« Reply #5 on: December 03, 2020, 09:15:02 AM »
Nice! It works" Thx u very much!  :)