playMaker

Author Topic: Resources Load  (Read 43431 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15594
  • Official Playmaker Support
Resources Load
« on: May 17, 2013, 02:03:21 AM »
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, 03:01:03 AM by jeanfabre »

junglist

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Resources Load
« Reply #1 on: June 24, 2013, 01:43:23 PM »
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: 15594
  • Official Playmaker Support
Re: Resources Load
« Reply #2 on: June 25, 2013, 02:53:49 AM »
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
Re: Resources Load
« Reply #3 on: June 25, 2013, 03: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: 15594
  • Official Playmaker Support
Re: Resources Load
« Reply #4 on: June 25, 2013, 03: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
Re: Resources Load
« Reply #5 on: June 25, 2013, 01:25:05 PM »
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: 15594
  • Official Playmaker Support
Re: Resources Load
« Reply #6 on: July 04, 2013, 03: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
Re: Resources Load
« Reply #7 on: August 01, 2013, 04: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: 15594
  • Official Playmaker Support
Re: Resources Load
« Reply #8 on: August 02, 2013, 08:56:54 AM »
Hi,

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

Bye,

 Jean

FractalCore

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 100
Re: Resources Load
« Reply #9 on: October 04, 2013, 04: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
    • Little Worlds Interactive
Re: Resources Load
« Reply #10 on: September 25, 2014, 03: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: 2511
  • Mender of the past
    • Cleverous
Re: Resources Load
« Reply #11 on: September 26, 2014, 11: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.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

JennaReanne

  • Junior Playmaker
  • **
  • Posts: 57
    • Little Worlds Interactive
Re: Resources Load
« Reply #12 on: September 29, 2014, 09: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: 687
    • Assets
Re: Resources Load
« Reply #13 on: December 19, 2014, 05: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, 08:07:36 PM by LampRabbit »

jeanfabre

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

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

Bye,

 Jean