playMaker

Author Topic: PoolManager and XML [SOLVED]  (Read 1964 times)

DennisJensen

  • Full Member
  • ***
  • Posts: 104
PoolManager and XML [SOLVED]
« 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.
« Last Edit: April 05, 2017, 08:16:23 AM by DennisJensen »
Game Designer, CEO, Artist
http://2ndStudio.com

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: PoolManager and XML
« Reply #1 on: April 03, 2017, 01:30:25 PM »
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

Code: [Select]
Transform myInstance = PoolManager.Pools["Shapes"].Spawn(myPrefab.transform);
Without pool manager it would be something like that:

Code: [Select]
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...

DennisJensen

  • Full Member
  • ***
  • Posts: 104
Re: PoolManager and XML
« Reply #2 on: April 03, 2017, 03:27:18 PM »
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:
Code: [Select]
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;
}
Game Designer, CEO, Artist
http://2ndStudio.com

DennisJensen

  • Full Member
  • ***
  • Posts: 104
Re: PoolManager and XML
« Reply #3 on: April 04, 2017, 04:13:38 AM »
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.
Game Designer, CEO, Artist
http://2ndStudio.com

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: PoolManager and XML
« Reply #4 on: April 04, 2017, 05:28:53 PM »
Yes, this line is responsible for instantiating

Code: [Select]
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...
« Last Edit: April 04, 2017, 05:31:39 PM by elusiven »

DennisJensen

  • Full Member
  • ***
  • Posts: 104
Re: PoolManager and XML
« Reply #5 on: April 05, 2017, 08:15:18 AM »
elusiven:


You are the best ! It did work. Awesome ! and thank you for the nice words :)
Game Designer, CEO, Artist
http://2ndStudio.com