playMaker

Author Topic: Resources Load  (Read 19755 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14059
  • Official Playmaker Support
    • View Profile
Resources Load
« on: May 16, 2013, 11:03:21 PM »
Hi Everyone,

 following a post: http://hutonggames.com/playmakerforum/index.php?topic=3904.msg18167#msg18167

Please find an action to load gameObjects, textures and materials from the resources folders in your assets based on the path of the asset.

Basically, this allow you to define the name of the asset using string, instead of having to maintain references. Also Working with Resources has special requirements, make sure you follow the guidelines:

http://docs.unity3d.com/Documentation/ScriptReference/Resources.html

[EDIT] new version with more checks to avoid error if resource is not found.
[EDIT: February 2014] now supported loading text assets in a FsmString.

Bye,

 Jean

« Last Edit: February 25, 2014, 01:01:03 AM by jeanfabre »

junglist

  • Playmaker Newbie
  • *
  • Posts: 21
    • View Profile
Re: Resources Load
« Reply #1 on: June 24, 2013, 10:43:23 AM »
this is great Jean! Would you please make a variation of this action that works like  this:

http://answers.unity3d.com/questions/425609/can-you-instantiate-random-prefabs-from-the-resour.html

whydoidoit's answer fetches a random prefab from a specified folder inside resources. We can just use playmaker's create object to spawn.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14059
  • Official Playmaker Support
    • View Profile
Re: Resources Load
« Reply #2 on: June 24, 2013, 11:53:49 PM »
Hi,

 you can do this already.

1: create the string representing your prefab name using actions such as "random int","int to string" and "build string"

2: inject that prefab name in "Resources Load" and done.

bye,

 Jean

junglist

  • Playmaker Newbie
  • *
  • Posts: 21
    • View Profile
Re: Resources Load
« Reply #3 on: June 25, 2013, 12:17:22 AM »
I just found this: http://hutonggames.com/playmakerforum/index.php?topic=3138.0

Combined with the actions you mentioned this will work. Thank you

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14059
  • Official Playmaker Support
    • View Profile
Re: Resources Load
« Reply #4 on: June 25, 2013, 12:30:57 AM »
Hi,
 
 I see, your issue was in finding out the number of prefabs in the resources. Thats' kind of dangerous cause you may have more prefabs in the end, not just the ones related to that particular feature.

bye,

 Jean

junglist

  • Playmaker Newbie
  • *
  • Posts: 21
    • View Profile
Re: Resources Load
« Reply #5 on: June 25, 2013, 10:25:05 AM »
I was assuming that much, but as long as I organize the folders/prefabs properly it should be perfect for my needs I think. I will be sure to post my results in this thread, thank you again for your input Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14059
  • Official Playmaker Support
    • View Profile
Re: Resources Load
« Reply #6 on: July 04, 2013, 12:05:50 AM »
Hi,

 Small improvements, now it will not throw errors if resource is not found ( especially with prefabs).

bye,

 Jean

mohvisuals

  • Playmaker Newbie
  • *
  • Posts: 14
    • View Profile
Re: Resources Load
« Reply #7 on: August 01, 2013, 01:43:42 PM »
I am unable to get this to work.

I have a folder called Resources and within that I have a prefab named Sphere.

Resources/Sphere is my Asset Path

I have the Type set to GameObject and the variable set.

What am I missing?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14059
  • Official Playmaker Support
    • View Profile
Re: Resources Load
« Reply #8 on: August 02, 2013, 05:56:54 AM »
Hi,

 You are likely having a typo in the reference of the resource.

Bye,

 Jean

FractalCore

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 97
    • View Profile
Re: Resources Load
« Reply #9 on: October 04, 2013, 01:55:42 AM »
I just tried your Sphere example. It's already looking in Resources so you don't include that in the Asset Path. Just putting Sphere in the Asset Path works.

JennaReanne

  • Junior Playmaker
  • **
  • Posts: 57
    • View Profile
    • Little Worlds Interactive
Re: Resources Load
« Reply #10 on: September 25, 2014, 12:46:57 PM »
This action is great - thank you Jean!  It looks like it both loads and instantiates prefabs in the scene; would it be possible to adjust this action or create a new one that gives us the option to just load a prefab into a variable?  Then we can use Create Object to define where we want to prefab to load in the scene.

Thank you!
Best,
Jenna

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: Resources Load
« Reply #11 on: September 26, 2014, 08:01:41 AM »
Hey Jenna,

Did this solve your problems here? Or did you need this action possibly extended or more functionality? Just want to make sure it doesn't get buried and be unsolved.

JennaReanne

  • Junior Playmaker
  • **
  • Posts: 57
    • View Profile
    • Little Worlds Interactive
Re: Resources Load
« Reply #12 on: September 29, 2014, 06:54:12 AM »
Hi Lane - I realized that the behavior I described in that thread was actually normal for Unity (I'll go back and update it!), so I'm using resource loading to help alleviate the memory issues.  I'm somewhat constrained in my use of the Resource Load action, though, because it instantiated a prefab as soon as it loads it.  It would be nice to have the option to just load it into a variable, then create it with a later action.

Thanks,
Jenna

escpodgames

  • Hero Member
  • *****
  • Posts: 686
    • View Profile
    • Assets
Re: Resources Load
« Reply #13 on: December 19, 2014, 03:26:13 PM »
New version of the action with the ability to load AudioClips

Set the variable to Object and the Results variable to Object UnityEngine.AudioClip
« Last Edit: December 19, 2014, 06:07:36 PM by LampRabbit »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14059
  • Official Playmaker Support
    • View Profile
Re: Resources Load
« Reply #14 on: January 19, 2015, 12:05:28 AM »
Hi,

 Very good, I have added the changes it to version available on the Ecosystem

Bye,

 Jean