Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

(SmartPool) Changing pool name in inspector

Discussion in 'Scripting' started by serbusfish, Jun 30, 2017.

  1. serbusfish

    serbusfish

    Joined:
    Dec 27, 2016
    Posts:
    247
    I got a Pool script from the asset store (SmartPool) and you access each pool you have created via script, like this:

    Code (csharp):
    1. SmartPool.Spawn("Pool1");
    But as I have lots of pools containing different things I am having to make a fresh script file for every single pool. I would love to be able to alter the name of the pool in the inspector so I dont need a load of scripts that all do the same thing, is this possible?
     
  2. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    Sure... you can create a string variable and just declare it public. then set it in your property inspector.

    Code (CSharp):
    1. // declaration section of your class/script...
    2. public string poolName;
    3. ....
    4. // wherever you call your pool...
    5. SmartPool.Spawn(poolName); // you might want to check if the string is empty first

    I use FastPool instead, which uses integers rather than strings for pool names (harder to remember, but typically a bit better to store), but basically I have a wrapper for my pooling calls that I call my PoolManager. I just make a call to it to spawn whatever it needs, passing the pool ID by a variable. The concept for SmartPool would be similar.. there's actually a demo project I found here too: https://gist.github.com/zaun/067b87ecd6cc1a2d896f14508c04f968

    Only thing is, that demo doesn't use a variable for the pool name, it's actually hard coded. But that's a very simple switch (see my code above).
     
  3. serbusfish

    serbusfish

    Joined:
    Dec 27, 2016
    Posts:
    247
    Unfortunately that is the method I tried to start with and it doesn't work with SmartPool. Im not sure why, but the name of the pool is set up like a tag (("Pool1").

    I might check out FastPool, but SmartPool was free and it does work well as a simple pool manager.
     
  4. CloudKid

    CloudKid

    Joined:
    Dec 13, 2015
    Posts:
    207
    I think you made a mistake as @cstooch idea should work for sure!
     
  5. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    Oh I'm sure SmartPool is fine. I wasn't suggesting you use something different. Just saying I wasn't 100% familiar with SmartPool, but it should work similarly.
     
  6. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    As for it not working.. not sure if you did something wrong? It should work....

    In your property inspector you only type: Pool1
    Make sure you don't put quotes.

    I don't see why that wouldn't work. If it didn't work, was there an error, or what happened? Perhaps share the code you put.
     
  7. serbusfish

    serbusfish

    Joined:
    Dec 27, 2016
    Posts:
    247
    I found the problem, the quotes where still there :oops:

    Thanks, it works now! :)