Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: DennisJensen on April 03, 2017, 09:54:23 AM
-
Hi,
I have a question about when PoolManager and XML works together.
I store the prefabs names of my items in my XML document. Which works fine, I then use "Resource Load" to get my prefab name from a path but that also spawns a game object. So that means I can't use "Resource Load" combined with PoolManager? Or how would you do that?
I need to define what Object I'm spawning and find it in my XML document, and then find that object in my object pool. but how?
Thank you guys, it means a lot.
-
Resource load spawns an object? As far as I am aware, it loads an object into a variable.
Then with pool manager, it can be instantiated
Transform myInstance = PoolManager.Pools["Shapes"].Spawn(myPrefab.transform);
Without pool manager it would be something like that:
GameObject instance = Instantiate(Resources.Load("enemy", typeof(GameObject))) as GameObject;
As you can see, resource.load is passed in as a parameter in the instantiate method, so it does not instantiate by itself. I'l look into the action later, but I don't think it should do that by default...
-
I just store it as a Game Object but then it also instances one. I just double checked it order to see if I create a game object somewhere in my FSM but I don't.
I'm not a programmer, but I found this in the action, maybe that's why:
case VariableType.GameObject:
GameObject source = (GameObject)Resources.Load(assetPath.Value, typeof(GameObject));
if (source==null)
{
return false;
}
GameObject _go = (GameObject)Object.Instantiate(source);
if (_go==null)
{
return false;
}else{
FsmGameObject _target= this.Fsm.Variables.GetFsmGameObject(storeAsset.variableName);
_target.Value = _go;
}
-
Okay I found another thread where they talk about it as well.
Basically I store my prefab in my XML file, and that data is something I pull out in a string. I then use the string to find the prefab using "Load Resource" but since that instantiates a prefab in. it gives me trouble because I want to use a pool instead.
How do I pull data out from my XML sheet and spawn objects in my pool? I need somehow to convert my string to a game object, and also use that when I then spawn a new object from my pool.
-
Yes, this line is responsible for instantiating
GameObject _go = (GameObject)Object.Instantiate(source);
It instantiates and stores the game object in _go variable.
So I guess yours desired effect is to scrap the instantiating of the prefab and just leave it in the variable. I modified the Resource.Load action to work this way, it's attached to the post.
With this action it's just the case of creating a pool, then running the resource.load, storing the prefab in a gameobject variable and then using the create prefab tool action to spawn the prefabs.
Let me know if it works for you, and btw I love your designs on the website...
-
elusiven:
You are the best ! It did work. Awesome ! and thank you for the nice words :)