Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: Jake on January 01, 2013, 10:22:17 AM

Title: SmartPool released with custom actions
Post by: Jake on January 01, 2013, 10:22:17 AM
Hi,

our pooling solution SmartPool is live now at the AssetStore (http://u3d.as/3Se). It's custom actions are available at our website (http://fluffyunderware.com/pages/unity-plugins/smartpool.php).

Jake
Title: Re: SmartPool released with custom actions
Post by: jeanfabre on January 02, 2013, 06:16:06 AM
Hi Jake,

 added the link to the add ons on the wiki:

https://hutonggames.fogbugz.com/default.asp?W714

bye,

 Jean
Title: Re: SmartPool released with custom actions
Post by: gamedivision on January 17, 2013, 03:05:21 PM
ok i have a problem with my spawned object ive stored in a globalgameobject variable.the cube itself has added force attached to it,now the initial cube reacts to the force once spawned but all subsequent cubes just fall with no force at all
the easiest way to explain would be, the re-used cube doesn't react to the force added to the prefab after the initial spawn.

any ideas
 :)
Title: Re: SmartPool released with custom actions
Post by: Jake on January 17, 2013, 04:31:08 PM
Hi,

hmm, hard to guess what's going on. Is it possible that you send me a package that demonstrates the problem to jake<at>fluffyunderware<dot>com ? I'll look into it asap...

Thanks
Jake

Title: Re: SmartPool released with custom actions
Post by: gamedivision on January 17, 2013, 07:23:08 PM
Hi jake thanks for the speedy reply,I'm gona clean up the scene and when I finish work tomorrow ill post you it,I don't think it's anything to do with smartpool,I think spawning a particle explosion would do the same thing once the animation has gone through its cycle even though your repspawning the same object it wouldn't reset the animation
Title: Re: SmartPool released with custom actions
Post by: julius on February 01, 2013, 10:08:52 PM
Hey, in the SmartPool script on the asset store it has a #if UNTIY_4_0  instead of #if UNITY_4_0. Gave me a bunch of errors.

Also I wanted the create object functionality for setting a Spawn Point/Position/Rotation the network stuff is a little beyond me at the moment, but I added the rest. I haven't fully tested this script but the mini tests I've done work.

Code: [Select]

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("SmartPool")]
    [Tooltip("Spawn an object managed by a SmartPool")]
    public class SmartPoolSpawn : FsmStateAction
    {
        [Tooltip("The SmartPool being adressed")]
        [RequiredField]
        public FsmString smartPool;

        [UIHint(UIHint.Variable)]
        [Tooltip("Optionally store the created object.")]
        public FsmGameObject storeObject;

[Tooltip("Optional Spawn Point.")]
public FsmGameObject spawnPoint;

[Tooltip("Position. If a Spawn Point is defined, this is used as a local offset from the Spawn Point position.")]
public FsmVector3 position;

[Tooltip("Rotation. NOTE: Overrides the rotation of the Spawn Point.")]
public FsmVector3 rotation;

public override void Reset()
{
smartPool = null;
storeObject = null;
spawnPoint = null;
position = new FsmVector3 { UseVariable = true };
rotation = new FsmVector3 { UseVariable = true };
}


        public override void OnEnter()
        {
            if (!smartPool.IsNone)
{
                var go = SmartPool.Spawn(smartPool.Value);
storeObject.Value= go;

var spawnPosition = Vector3.zero;
var spawnRotation = Vector3.up;

if (spawnPoint.Value != null)
{
spawnPosition = spawnPoint.Value.transform.position;

if (!position.IsNone)
{
spawnPosition += position.Value;
}

spawnRotation = !rotation.IsNone ? rotation.Value : spawnPoint.Value.transform.eulerAngles;
go.transform.position = spawnPosition;
go.transform.localEulerAngles = spawnRotation;
}
else
{
if (!position.IsNone)
{
spawnPosition = position.Value;
go.transform.position = spawnPosition;
}

if (!rotation.IsNone)
{
spawnRotation = rotation.Value;
go.transform.localEulerAngles = spawnRotation;
}
}
}


Finish();
}
    }
}

Title: Re: SmartPool released with custom actions
Post by: Jake on February 03, 2013, 01:57:17 AM
Hi Julius,

thanks for pointing this out, I fixed and resubmitted it!

Regarding the Spawn-Action: the Spawn-Action returns the spawned object, so why don't you just initialize it in the State you're spawning it? Alternatively, OnEnable() will be called for the spawned object, so you can add any intitialization-code or calls to pM there.

Jake
Title: Re: SmartPool released with custom actions
Post by: julius on February 07, 2013, 06:21:35 PM
Hey Jake,

I'm hoping to be able to do the functionality via playmaker. I'm still pretty new to playmaker and unity so let me know if I'm completely off.

By initialize do you mean transforming the the deactivated smartpool object into place before running the SmartPool.Spawn()? or is there a way to use Instantiate without making a clone (which is still a costly behavior correct). If the former then I still couldn't use a playmaker action as I don't have access to the array in smart pool to find out which gameobject is the next array.pop. I wouldn't mind making a simple lookup function in smart pool to find the next gameobject to spawn if that is the case! I just want to make sure I'm not misunderstanding something as it is quite possible.

OnEnable() sets off the START state in a playmaker action so I could add the position rotation ect on the prefab via a playmaker FSM and it would effectively set those variable up, but I would still have to do that on the prefab and couldn't do it via the action above.

Anther question I had about SmartPool is how it handles child transformation changes. Looking though the code I saw the that it resets the main GameObject position to zero, but does it do anything else to reset the GameObject to its prefab state?

Title: Re: SmartPool released with custom actions
Post by: Jake on February 08, 2013, 05:52:44 AM
H julius,

I'm not quite sure if I understand you right, but let me clarify two things:

1.) Smartpool "prepares" the pool at start (=instantiating n clones of the prefab until MinPoolSize is reached and disable the new GameObjects instantly, so no FSM/scripts will run). When you call Spawn(), one Object from the pool will be enabled (FSM's of this Object will start running as well as any other scripts attached!) and a reference returned to you. Besides setting localPosition to zero no other initialization happens.

2.) When you need to run logic for an object after spawning it, you have two options (related to playMaker): a.) in the FSM where you call the "SmartPool Spawn" action, store the returned object in a variable and do something with it afterwards (that's what I do in the example scene coming with pmSmartPool) or b.) Add an FSM to your prefab. After Spawn, the FSM of that object will start running and you can do some stuff there.

To sum this up, there's no need to know which object will be spawned next by SmartPool, you really shouldn't care about it.

Hope that helps
Jake

Title: Re: SmartPool released with custom actions
Post by: brendang on February 16, 2013, 06:02:50 PM
Argh,  Pooling is still voodoo to me, and I own SmartPool!

I'd like to describe to uses I imagine using the plugin for and maybe Jake or someone with pooling chops could tell me if these uses are what the pooling plugin would be used for.

1 - I have a 2D sidescroller. It's a bird flying over water. As the bird flies along, I'd like a random number (between 1-5) of random fish (there will be 12 different fish models/prefabs)  to be jumping out of the water for the bird to eat, within the Camera's view (the camera travels along with the bird). 

2- Imagine a room with several doors. Randomly, a random selection of 'monsters' (basically 12-20 2d sprites), would come crashing out of one or more of the doors toward camera for you to shoot.

I guess I'm wondering if 'pools' should be composed of collections of different fish or monsters or cubes or whatever.  Can they be given random forces ( like the fish jump with different combinations of rigidbody.AddForce on X & Y for different heights and such).

Hopefully this makes some sense.

B.
Title: Re: SmartPool released with custom actions
Post by: Jake on February 17, 2013, 03:43:40 AM
Hi,

keep in mind that a pooling manager does nothing more than serve objects. Without a pooling manager, you keep references to your prefabs somewhere and instantiate and destroy them as needed. With a pooling manager you do exactly the same, but instead of instantiating and destroying you use Spawn() and Despawn(). With SmartPool, you don't neccessarely need to keep references to the prefabs, because you can optionally get them by their name.

So for each prefab, add a SmartPool object, assign the prefab, set properties and replace the instantiate and destroy commands with calls to SmartPool. In your first example, create 12 Smartpool components, assign the 12 Prefabs and name the pools by number, e.g. Fish0, Fish1, Fish2 etc...

In your code, when you need a random fish, do "myFish=SmartPool.Spawn("Fish"+Mathf.Random(0i,11i));" to get a random fish. After receiving the fish, initialize it like you would without SmartPool and you're done. Wen you don't need the fish anymore, use "SmartPool.Despawn(myFish)" to return it to the pool.

Jake

Title: Re: SmartPool released with custom actions
Post by: brendang on February 17, 2013, 07:53:57 PM
In your code, when you need a random fish, do "myFish=SmartPool.Spawn("Fish"+Mathf.Random(0i,11i));" to get a random fish. After receiving the fish, initialize it like you would without SmartPool and you're done. Wen you don't need the fish anymore, use "SmartPool.Despawn(myFish)" to return it to the pool.

Jake

What code?  I thought the purpose of integrating SmartPool with PM was using actions?   I'm sure this makes complete sense to you, which is handy, since you wrote it. but it's a wee bit vague to me.   I think the issue is you are not discussing this in "Playmaker terms" your instructions. Have you worked with the Playmaker actions much as they relate to SmartPool?

Also, the pm_example project comes in broken?   I start with a new project, import Playmaker, Import SmartPool and then import the Playmaker actions for SmartPool and this is how it shows up in the Inspector. And nothing seems to have an FSM attached.

(https://dl.dropbox.com/u/1413577/Screen%20Shot%202013-02-17%20at%208.11.52%20PM.png)

Clearly I'd hook the bullet into the bullet, and the Brick into the brick. but which script goes into the PlayMakerGUI and which into the Mono Behavior beneath the two SmartPool scripts attached to the SmartPools Gameobject?
(https://dl.dropbox.com/u/1413577/Screen%20Shot%202013-02-17%20at%208.20.17%20PM.png)
Title: Re: SmartPool released with custom actions
Post by: Alex Chouls on February 17, 2013, 09:00:39 PM
Regarding the Missing (Mono Script). Sometimes Unity loses references to scripts. You can restore the reference by selecting the browse button and selecting the appropriate component: PlayMakerFSM for the FSMs and PlayMakerGUI for the GUI component.

But it looks like the example project is missing other references too... so there might be other problems with the example project...
Title: Re: SmartPool released with custom actions
Post by: Jake on February 18, 2013, 03:22:36 AM
Hi,

I've updated pmSmartPool (download here (http://www.fluffyunderware.com/pages/downloads.php)), the examples should work now. I exported the package with Unity 3.5 and playMaker 1.4.x and I've tested it by creating a new project in Unity 4, imported playMaker 1.5 + SmartPool 1.01 + pmSmartPool.

All you have to do after loading a scene (e.g. pmExample) is to add the missing playmakerFSM script to the SmartPool gameobject (like Alex said). After adding the script, click on "edit" before you play the scene, otherwise you'll get a runtime error.

I also added a scene pmRandomSpawn showing how to spawn a random object.

Jake

PS: Sorry for not discussing this in playMaker terms. I'm a coder and from my point of view an action is equivalent to a few lines of code. I primarily use playMaker to create higher level FSMs while most functionality is done in code. I'll try to think more action focused in my future answers, promised!
Title: Re: SmartPool released with custom actions
Post by: brendang on February 18, 2013, 08:46:33 AM
Really appreciate the help help, Jake.  coffee first, Playmaker and Smartpool right after.


best,
B.
Title: Re: SmartPool released with custom actions
Post by: brendang on February 18, 2013, 11:02:47 AM
Jake, did you see my post on your own forum?
Title: Re: SmartPool released with custom actions
Post by: Lobohotpants on March 14, 2013, 11:49:44 PM
I'm using photon to instantiate my objects over the network.  Can I still use smartpool?  How does the spawning work in this case?
Title: Re: SmartPool released with custom actions
Post by: Jake on March 15, 2013, 05:26:45 AM
Hi,

The key question will be if Photon is able to tell you that an object needs to be created instead of creating it directly. So if Photon has an event for this, the use of SmartPool is possible.

I never worked with Photon, so hopefully someone else can answer this. If not, I'm gonna checkout Photon this evening to give you a qualified answer then.

Jake
Title: Re: SmartPool released with custom actions
Post by: Mayhem on March 15, 2013, 05:43:08 AM
So i read through this topic and before i buy SmartPool i wanted to know if it is fully functional with PlayMaker. Are there some other errors? And is it compatible with Unity 3.5 ?
Title: Re: SmartPool released with custom actions
Post by: Jake on March 15, 2013, 06:13:03 AM
Hi Mayhem,

Quote
So i read through this topic and before i buy SmartPool i wanted to know if it is fully functional with PlayMaker.
Yes, all major commands are covered by custom actions, in detail:
Only GetPoolByItem / GetPoolByName aren't covered, but I can't think of a playMaker scenario that will need those methods. However, I'll implement them if requested by one of my customers.

Quote
Are there some other errors?
Other than what errors? I don't know of any unfixed errors.

Quote
And is it compatible with Unity 3.5 ?
Yes, it is, the AssetStore package was submitted using Unity 3.5.7.

Jake
Title: Re: SmartPool released with custom actions
Post by: Mayhem on March 15, 2013, 06:29:00 AM
Allright, thank you :)

Refering to the errors:

For example:

Quote
Hey, in the SmartPool script on the asset store it has a #if UNTIY_4_0  instead of #if UNITY_4_0. Gave me a bunch of errors.

I know that you solved that, but i just wanted to be sure there are not any other problems you might heard of in your forums or something like that :)

Thanks for the support, i will go and grab it :D
Title: Re: SmartPool released with custom actions
Post by: Jake on March 15, 2013, 08:03:33 AM
Quote from: Mayhem link=topic=2844.msg15492#msg15492
I know that you solved that, but i just wanted to be sure there are not any other problems you might heard of in your forums or something like that :)

Ah, ok  ;D If I get aware of problems/errors in one of our packages, I'll fix them asap and (if it takes longer) write about temporary workarounds until the updated package arives in the assetstore.

Interestingly I don't get many error reports from our customers. I don't know exactly why. Some errors I found&fixed by myself must have been realized by others, too, so I wonder why noone wrote a short note to get it fixed...

Quote
i will go and grab it

Thank you very much! Don't forget to vote it in the Assetstore, we really appreciate this.

Cheers,
Jake
Title: Re: SmartPool released with custom actions
Post by: Mayhem on March 15, 2013, 09:25:13 AM
Just another question, nothing PM specific though.

Is it possible to compare Tags between Objects in the Scene and Objects in the Poolmanager, whether they are spawned or not.
Title: Re: SmartPool released with custom actions
Post by: jeanfabre on March 15, 2013, 10:11:00 AM
Hi,

 I don't see why photon and pooling would not work together just fine. Photon instantiate a prefab that MUST be in the Resources folder, that's the only requirement, then of course the gameObject should have a photon view component attach, but that's not something that would get in the way of the pooling system.

bye,

 Jean
Title: Re: SmartPool released with custom actions
Post by: Jake on March 15, 2013, 04:37:49 PM
@jean: I had a quick look at PhotonNetworkInstantiate.cs. Shouldn't it be sufficient to copy&paste this into a new script and replace the prefab instantiation with a call to Pool.Spawn() ?

@Mayhem: Do you want to check if an object was spawned by a pool? That's possible (IsManagedObject() and IsSpawned()), though not accessable through pm actions right now. I can provide those actions, if you want.

Jake
Title: Re: SmartPool released with custom actions
Post by: Mayhem on March 15, 2013, 04:41:23 PM
That would be amazing! :D
Title: Re: SmartPool released with custom actions
Post by: Jake on March 15, 2013, 05:02:28 PM
Ok, I'll add them. For what scenario do you need them? I ask because I've changed Despawn() in v1.2. If you call it with an unmanaged object, that object now will be destroyed. So calling Despawn(gameObject) ensures that the object will be always gone. Just in case that solves your problem...
Title: Re: SmartPool released with custom actions
Post by: Mayhem on March 15, 2013, 08:51:05 PM
I want it for my Inventory-System and checking which Item was picked up.
Title: Re: SmartPool released with custom actions
Post by: jeanfabre on March 18, 2013, 02:57:09 AM
Hi Jake,

 yes, you will likely have to make a custom action to instantiate your player using a pooling system.

bye,

 Jean
Title: Re: SmartPool released with custom actions
Post by: Jake on March 19, 2013, 02:45:03 PM
SmartPool v1.02 has arrived in the AssetStore and the custom actions package has been updated!
Title: Re: SmartPool released with custom actions[SOLVED]
Post by: jay.pis on March 19, 2013, 05:58:47 PM
I have a multiplayer project that I'm working on and I need to spawn the following: 20 bags with 3 random items spawning inside each bag and spawning random items in selected areas of the map that players can pick-up and use, items do not re-spawn after they are picked up.

Would I need something like SmartPool or not really since I'm not needing to spawn and destroy lots and lots of objects? Can I accomplish this with just playMaker alone?
Title: Re: SmartPool released with custom actions
Post by: Lobohotpants on March 19, 2013, 09:56:24 PM
@jean: I had a quick look at PhotonNetworkInstantiate.cs. Shouldn't it be sufficient to copy&paste this into a new script and replace the prefab instantiation with a call to Pool.Spawn() ?

Could you go into a little more detail about this?  I'd be very interested in using it.
Title: Re: SmartPool released with custom actions
Post by: Jake on March 20, 2013, 03:41:01 PM
Another (even better idea) is to use "PhotonViewRpcBroadcastFsmEvent" to send an pM event over the network. You then can spawn/despawn Smartpool like you would locally.
Title: Re: SmartPool released with custom actions
Post by: Sonic Punch Studio on April 15, 2013, 11:36:46 PM
Hi there, I've just started integration of SmartPool into my project but I'm kinda running into a snag here. You see, I've followed the instructions and stuff (create game object, attach SP component, linked a prefab) but when the pool preps itself on start up the stored prefabs will show up visible and paused in the middle of the screen (0,0,0).

Am I missing a step here? Is there a way to make it so that the pool will prep out of sight?

EDIT: Finally figured out the problem - had to enter some otherworldly figure in one of the position axis for it to initialise off screen.
Title: Re: SmartPool released with custom actions
Post by: jeanfabre on April 16, 2013, 12:26:09 AM
Hi,

 Have you contacted the author of smartPool? it could be likely be a setup of the pool itself or is it something that only happens within the playmaker environment?

bye,

 Jean
Title: Re: SmartPool released with custom actions
Post by: Sonic Punch Studio on April 16, 2013, 12:36:29 AM
Hi Jean, just figured out the problem and had edited my original post accordingly. Thanks for the response :D
Title: Re: SmartPool released with custom actions
Post by: Jake on April 17, 2013, 04:21:38 PM
Hi,

sorry for the late answer. This is strange, because Smartpool disables all prefabs when preparing a pool, so all objects should be invisible as a result.

Would you mind to send me more information about this issue, e.g. a way to reproduce this or a ripped down sample project? I'll definitely will look into this asap.

Jake (jake@fluffyunderware.com)
Title: Re: SmartPool released with custom actions
Post by: Sonic Punch Studio on April 19, 2013, 02:58:23 AM
Well, if it helps, the thing is I'm using SP on Unity 3.5.6f4 despite the original requirement for Unity 3.5.7f (3.5.7f is preventing me from successfully building android .apk's so I had to roll back with SP still in the project folder).

One way to reproduce this is to just simply link a prefab to a pool and then have it prepare automatically on runtime. In my case I've taken no other steps beyond that.

- 2ndBrother
Title: Re: SmartPool released with custom actions
Post by: Jake on April 19, 2013, 11:34:43 AM
Hi,

SP should work with even older Unity version. I'll try to reproduce this later today and report back.

Thanks
Title: Re: SmartPool released with custom actions
Post by: Jake on April 19, 2013, 03:24:56 PM
Hm, I can't reproduce this. If've tested the sample scenes shipping with SmartPool (Example and pmExample) as well as a pool created from scratch in a new scene, and everything work's like intended: the objects were instantiated but disabled.

Perhaps there is something special with the prefab itself? From here it sounds like your prefabs enable themself somehow. If you start the game, can you please expand the pool object in the Hierarchy window and see if the prefabs are there both disabled and their name ending with "_stock" ?

Thanks
Jake
Title: Re: SmartPool released with custom actions
Post by: Sonic Punch Studio on April 20, 2013, 06:58:03 AM
Well that's the thing - the instantiated prefabs are disabled with "_stock" at the end of the names YET they are visible. Normally disabled objects should be not visible but not the case with these pool-instantiated prefabs.

- 2ndBrother
Title: Re: SmartPool released with custom actions
Post by: Jake on April 20, 2013, 07:33:04 AM
Interesting, I've never seen that before and I think it must be a Unity bug. Do this even happens with the example prefabs (or another simple primitive turned into a prefab)? If not, what components are inside the Prefab?

Btw, what are your system specs?
Title: Re: SmartPool released with custom actions
Post by: Mayhem on April 22, 2013, 12:51:16 PM
Hey there, in the Review-Section of the AssetStore someone wrote that the PlayMaker Example doesn't work. Is that true?
Title: Re: SmartPool released with custom actions
Post by: Jake on April 23, 2013, 11:12:25 AM
No, this is wrong! And he should have asked before stating that SmartPool doesn't work with playMaker, just because an example scene was broken by Unity again (because Unity isn't capable of referencing updated scripts, see http://hutonggames.com/playmakerforum/index.php?action=search2).

We'll repackage the example scenes against the latest playMaker version later today. Until then, just drag the scripts manually back in, the settings will remain.

Jake