Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

LEAN ⚡️ Touch / GUI / Texture / Localization / Transition / Pool

Discussion in 'Assets and Asset Store' started by Darkcoder, Aug 1, 2019.

  1. mkimbro

    mkimbro

    Joined:
    Apr 7, 2020
    Posts:
    2
    Hello - I am trying to use Lean Touch in a game where the player picks up objects to investigate them. I would like for the player to use 1 finger to rotate the object and for the object to rotate relative to its current rotation.

    The action I'm hoping to accomplish would be similar to what can be achieved with the rotate tool in the Unity editor as shown here:



    I've gotten close by using Lean Multi Update's On Delta connected to LeanPitchYaw.Rotate but the rotations are relative to the object and not the player - for example, if I swipe up, the object always rotates on the X axis locally. That works if X is the only axis on which the player has rotated the item but if it's sideways, the rotation no longer matches the swipe direction.

    I'm sure I'm missing something simple but I've been trying and failing for some time now and would appreciate any tips!
     
  2. noahx

    noahx

    Joined:
    Nov 22, 2010
    Posts:
    77
    Hi. Is there any way or guide on how to integrate Lean Touch to work with NGUI? Specifically I'm interested in the Tap to Select component, with the option to ignore over GUI.

    Thanks.
     
  3. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    Great. The next version will feature the DisableMouseEmulation setting, which can be used to disable this setting, and it will be enabled by default because I don't think many users will need it if they're using Lean Touch.

    I'll send you a test script via private message.


    You would have to modify the code yourself to do this (e.g. LeanTouch.RaycastGui and related methods). I've never used NGUI so I don't know what would be required, nor do I wish to support it.
     
    Malveka likes this.
  4. BigToe

    BigToe

    Joined:
    Nov 1, 2010
    Posts:
    208
    I ran into a situation where I can't figure out how to create sequences that have more than one transition in the second part of the sequence.

    I have 3 transitions that fire.
    I have a join.
    Then I have 2 transitions that I would like to fire at the same time.

    But I can’t figure out how to do that. The second transition in the second group cancels out it’s counterpart in the first group. If I add another join, it waits for the transition above it to finish so I have 3 steps instead of two.
    I have included a diagram of what I am trying. I’m sure I am missing something.

    Thanks in advance for your help.

    LeanTransitionIssue_v01.png
     
    Last edited: Jan 20, 2022
  5. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    JoinTransition makes it so the next transition begins after the previous transition ends. Without this, each transition is considered separate and will execute at the same time. This is why in the left image, the last transition isn't 'grouped' to the one before it, because it's not joined to anything.

    To make it behave like this you can use the nesting/branching feature, as seen in the "04 Branches" demo scene.
     
  6. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    343
    I have a question and a possible bug report.

    1. Question. I would like to use LeanTooltips with no transitions (instant popup). Is it recommended to set the transitions to zero to accomplish this?

    2. Bug. There's something funky with the 01.Point and 02.Offset scenes in Lean GUI Shapes. The red sphere mesh doesn't show up in either the game window or scene window.
     
  7. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    1 - Sure, you can also use the OnShow/OnHide events to enable/disable the element.

    2 - Thanks for pointing this out. These scenes use an orthographic camera, and the Clipping Planes / Near was set too low, causing the skybox to draw in front of the red sphere. This will be fixed in the next version.
     
  8. ProductiveHippo

    ProductiveHippo

    Joined:
    Jan 7, 2022
    Posts:
    9
    Hello, firstly thank you for this asset. It’s great.

    I have a few different touch requirements for my project which I am struggling to tie together
    • Camera pinch zoom. Should only work when the touch’s did not begin over a tagged gameobject
    • Camera drag to pan. As above.
    • Gameobject tap to select
    • Gameobject drag to move
    The issue I’m struggling with is tying the different elements together so that (for example)
    • if I drag across the screen it understands that this is a “camera pan” and ignores that I touched a gameobject in the process.
    • If I drag a gameobject around it knows I’m not panning the camera

    any help much appreciated!
     
  9. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    The LeanSelectedCount component can be used to fire an event when you have 0 or any number of objects selected. This can be used to enable or disable your camera controls. I don't remember off the top of my head if there is an example scene for this, but it should solve your issues.
     
  10. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    343
    I'm having issues with Lean Drag Camera in a top down scenario. I find it to be very sensitive and when trying to click on a unit, the camera will often move 1 pixel instead. I thought it was my Tap/Swipe thresholds but those seem to have no affect on this component. Ideally, I want the camera to only move after x pixels of dragging.
     
  11. hieutran196

    hieutran196

    Joined:
    Dec 17, 2018
    Posts:
    21
    Hi,
    Thank you for your great asset (Lean Pool).
    Does LeanPool work with WebGL?
    ----
    When I used LeanPool, my code works well on Editor but not working on WebGL, no errors appear :( I don't no why.
    I change from LeanPool to Instantiate() and Destroy(), my code work again on WebGL :(.
     
  12. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    The distance LeanDragCamera moves depends on your ScreenDepth setting. For example, if you use FixedDistance then the lower the distance, the less the camera will move.

    To only activate this component after a certain amount of movement you could use the LeanGestureToggle component from LeanTouch+, which activates the specified DragComponent setting if you do a drag gesture beyond the DragThreshold setting distance.


    Lean Pool should work on all platforms. Without being able to replicate this in a simple demo I have no idea what might be going wrong.
     
    hieutran196 likes this.
  13. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    343
    Thanks for the LeanGestureToggle hint. By itself, deactivating LeanDragCamera was killing the inertia but I managed to come up with a hacky solution that toggles fingers required between 0 and 11. This keeps LeanDragCamera active but not directly usable. Let's hope I don't have any players with extra thumbs!
     
  14. hieutran196

    hieutran196

    Joined:
    Dec 17, 2018
    Posts:
    21
    Hi, I resolved it. Down version from 2021 to 2020 and it works.
    ------
    Pls help me one more question:
    I create LeanGameObjectPool to scene and preload 100 gameobjects when load scene, that 100 gameobjects contain my specific script, ex: <T>. That's why every time I Spawn, I have to GetComponent<T> to call Setup() function in <T>. I think it is not good for performance when call GetComponent many times in game.
    Is there any method support cache specific script?
    Please help. Thank you.
     
  15. unity_5F3233DDF34AF1474DBC

    unity_5F3233DDF34AF1474DBC

    Joined:
    Dec 11, 2021
    Posts:
    18
    Hello, I'm having a problem with leantouch free plug-in. you see my app is instantiating a 3d file from local file storage and adding the lean touch scripts in code meaning before I instantiate the object I add the scripts of lean touch using the command AddComponent (e.g.
    _loadedGameObject.AddComponent<LeanPinchScale>();
    )

    my problem now is all the objects are moving and scaling at the same time. So I've look at the website and it says that adding a leantouchselectable component will fix it but it doesn't though. So I've gone to the next step where we add Leanfingertap and leanselectbyfinger but since I'm adding them in the code I cannot do the step where we add the leanselectbyfinger.selectscreenposition function to the on the onfinger event of leanfingertap. I tried to modify it the leanfingertap so that it will not be serializable instead it will run automatically the script of selectscreenposition but so far icant make it to work. any hands on this?
     
  16. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    That's one way to do it. Some components have a 'Listening' setting which works better than enabling/disabling the component. Maybe I should add this to all the components, and extend LeanGestureToggle to have events so it can toggle this instead.


    Run your code in Awake?


    Adding the LeanSelectable/ByFinger component will only automatically work in the editor. When adding this component from code you must then manually assign this component instance to the Use.RequiredSelectable field of your LeanPinchScale component.
     
  17. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    343
    That's probably a good idea. Disabling components can be unpredictable and messy. I recently switched to using Canvas Group on my UIs and toggling the Alpha property because disabling components was breaking scripts and causing canvas refresh problems.
     
    Darkcoder likes this.
  18. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    568
    Anyone having problems with Lean Touch and Device Simulator?

    My clicks/taps work fine in game view, and the device, but not when I enable Device Simulator.
     
  19. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    Yeah I've added this to the (very long) to-do list. When I have more time I'll look into it.

    The device simulator gives bad values so you shouldn't use it.
     
  20. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    568
    Thank you for your response. What do you mean by "bad values"?
    Works fine with other assets and features.
     
  21. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    343
    I'm working on an inventory system and I would like to make a suggestion for LeanHover to add a checkbox for "Ignore if mouse button down".

    My usage scenario is highlighting something on hover, picking that item up, and dragging it elsewhere. As of now, the other items are highlighted/triggered as the mouse drags past them and makes for a confusing situation. I'm currently using if (!Input.GetButton("Fire1")) but it would be better if it was an option in the inspector.
     
  22. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    Another used reported that Unity's device simulator can give NaN values or something like this under some circumstances which Lean Touch doesn't expect (because real devices don't seem to do this), and this can cause some things to break. I think the exact situation was that emulating touches also reports that there is a mouse present, and this mouse had bad data that Lean Touch is reading.


    That's one way to do it. Lean GUI was designed to work the same on both desktops and mobile though, so it wouldn't be a good solution for everyone. I think a better idea would be to enable/disable the LeanTooltipData component based on click/drag/etc, then it would work the same on all devices. It looks like LeanTooltip doesn't detect when a hovered tooltip gets disabled though, so I'll fix that for the next release.
     
    JohnnyFactor likes this.
  23. hieutran196

    hieutran196

    Joined:
    Dec 17, 2018
    Posts:
    21
    Run your code in Awake?.
    I mean:
    1. I create GameObjectPool in scene and preload 100 Units when my scene loaded.
    upload_2022-2-18_11-26-53.png
    2. I created a singleton to ref to Pool
    upload_2022-2-18_11-31-32.png
    3. And when I want to spawn unit, and set up unit, I have to call
    GetComponent (line 130) every time when I spawn. I think it is not good for perfomance when call GetComponent many times.
    Is there anyway to not GetComponent but I still get Unit script?
    upload_2022-2-18_11-34-56.png

    Thank for your help!
     
  24. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    Oh I see. Well as the name implies this class works using GameObjects, so it's not possible to directly get a component without using GetComponent. I believe internally Instantiate runs GetComponent the same way as the main LeanPool component works when you use components too. If this one GetComponent call is really a performance issue then you should implement your own pooling solution that uses components directly.
     
  25. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    568
    I see. Well, we had also gotten some NaN errors too, but this was mainly due to our oversight. Forgot to properly address an object after renaming it. After fixing our script it got fixed. It is not related to the Simulator though.
     
    Darkcoder likes this.
  26. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    Yeah this is on my to-do list to look into. However, I'm currently really busy updating all my assets for some other things. Since this issue is a bug with Unity's code sending nonsense values you can imagine it's not high on my priority list to work around.
     
  27. brainode

    brainode

    Joined:
    Sep 24, 2018
    Posts:
    1
    Hi all! Sorry, if i duplicate someone question, but i can't find post using my keywords. The question is, how to combine 2 modules from Lean Touch+, i want to combine Lean Finger Held and Lean Finger Down Canvas, to check, if finger was held over UI element more than 2 seconds. How it could be achieved?
     
  28. Fariborzzn

    Fariborzzn

    Joined:
    Apr 17, 2019
    Posts:
    14
    Hey was looking at Lean Pool Class and didn't find a method for creating pool dynamically , in my game I have different agent to spawn and don't wanna create pool at editor statically cause there will be time a agent will not be in game but the pool will be was wondering what is the best approach to create pool dynamically bas on agent existence plus the pool setting need to be set before creating the pool ,
    Thanks for your amazing asset love it so far :)
     
  29. Fariborzzn

    Fariborzzn

    Joined:
    Apr 17, 2019
    Posts:
    14
    Here is the code if anyone is interested to Create Pool At Runtime With Specific Setting
    The Scriptable Object store data for unit Pool Setting :
    (It Doesn't need to be scriptable object you can use serializable class too)

    Code (CSharp):
    1.  
    2.     /// <summary>
    3.     /// Pool setting
    4.     /// </summary>
    5.     [CreateAssetMenu(fileName = "PoolSetting.asset", menuName = "Pool", order = 1)]
    6.     public class PoolSetting : ScriptableObject
    7.     {
    8.         public LeanGameObjectPool.NotificationType notification = LeanGameObjectPool.NotificationType.IPoolable;
    9.         public LeanGameObjectPool.StrategyType strategy = LeanGameObjectPool.StrategyType.ActivateAndDeactivate;
    10.         public int preload;
    11.         public int capacity;
    12.         public bool recycle;
    13.         public bool persist;
    14.         public bool stamp;
    15.         public bool warnings = true;
    16.     }
    and This method will create pool for you at runtime :

    Code (CSharp):
    1.    
    2.         /// <summary>
    3.         /// Creat pool for specific game object at runtime
    4.         /// </summary>
    5.         /// <param name="clone"></param>
    6.         /// <param name="setting"></param>
    7.         private void CreatPool(GameObject clone, PoolSetting setting)
    8.         {
    9.             var pool = default(LeanGameObjectPool);
    10.  
    11.             // Create a new pool if there is not a pool associate with this game object
    12.  
    13.             if (LeanGameObjectPool.TryFindPoolByPrefab(clone, ref pool) == false)
    14.             {
    15.                 pool = new GameObject(clone.name).AddComponent<LeanGameObjectPool>();
    16.              
    17.                 pool.Prefab = clone;
    18.  
    19.                 pool.Capacity = setting.capacity;
    20.                 pool.Notification = setting.notification;
    21.                 pool.Strategy = setting.strategy;
    22.                 pool.Preload = setting.preload;
    23.                 pool.Recycle = setting.recycle;
    24.                 pool.Stamp = setting.stamp;
    25.                 pool.Warnings = setting.warnings;
    26.                 pool.Persist = setting.persist;
    27.              
    28.                 pool.PreloadAll();
    29.             }
    30.         }
    31.  
     
    hessex likes this.
  30. dnamarcel

    dnamarcel

    Joined:
    Jul 2, 2015
    Posts:
    2
    Hello my friend,
    sorry if this has been asked before,
    How can i "tab" between leanButtons using the joystick? And then perform a "click" also with Joystick?
    Im using new input system btw.
    Thank you
     
  31. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    I'll send you a private message with a new component.


    Nice work! Perhaps a little advanced for most users though. Although making one pool per prefab may not be the best solution, it is very simple to implement and should be good enough for most users.


    LeanButton implements the same navigation system as components like Unity's UI Button. This works using the Event System's input module axes which I think are supported by the new Input System.
     
  32. dimzki

    dimzki

    Joined:
    Apr 17, 2018
    Posts:
    12
    Hello!

    i have a problem that i cant seem to figure out what's actually causing it. im building a game for android.
    i have a function where you need to select a region of where you want to play the game (using 2D Sprite renderer with lean selectable by finger).

    so the flow is like this: player select region -> player given options of the factions that can be played on that region.
    but some players (not all) reported that they can't select the region.

    it works fine in editor, and even works fine in my phone (galaxy s9+) but some users are reporting trouble of not being able to click on the region (2D sprite renderer). i tried both unity old input system and new input system.

    when the bug first appeared, i was using raycast with collider to select the region, then i switched to use lean selectable by finger, but it still didn't work for some users. 1 user mentioned that they're using galaxy s9 (while im using s9+)

    i dont know why it works for my device but dont for some users (even with similar device). so here's the code that i have (attached to the selectable object (2D renderer))

    Code (CSharp):
    1. public class LeanSelectRegion : LeanSelectableBehaviour
    2.     {
    3.         [SerializeField] GameMasterTitle gmScriptTitle;
    4.         [SerializeField] int regionIndex;
    5.  
    6.         /// <summary>Called when selection begins.</summary>
    7.         protected override void OnSelected(LeanSelect select)
    8.         {
    9.             gmScriptTitle.RegionSelected(regionIndex);
    10.         }
    11.     }
    i'm using unity editor 2020.3.26f1, lean touch+ 3.0.0, unity's input system 1.2.0

    im not a professional programmer, im not sure how to debug the problem that users experiencing...
     
  33. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    Is it possible you have (invisible) UI elements that can block the region if users have different resolution or aspect ratios or device orientations? If selection works on your device then it should work the same on other devices too, so it's very likely some other reason is causing the selection to not work. Without either of us being able to replicate the issue, it would be very hard to track down what causes this. You must try and narrow it down to find what the correlation is between all the users that experience the issue.
     
  34. dimzki

    dimzki

    Joined:
    Apr 17, 2018
    Posts:
    12
    Hello, after i managed to get my hand on a test device that has the same problem, after looking at the logcat it turns out that the problem was not with the touch system. So i wasted about a 1.5 week trying to figure out the problem with the touch system while in fact the problem lies with the "awake" code on gameMaster that load basedata from json file could not find the data on some system due to the data not being present on build, but only on certain devices.

    fortunately it's all good now.
     
    Darkcoder likes this.
  35. nanditho

    nanditho

    Joined:
    Jan 10, 2018
    Posts:
    27
    Hello, I would like to perform object rotation on X, Y, and Z axis on swipe gesture regards to camera pan/rotation.

    So my main camera always target to one specific gameobject, and I would like to be able to pan / rotate my camera then do swipe / drag gesture to rotate the gameobject (on all the axis: x, y, z) on any angle of camera.

    How is it possible with the asset. Thanks
     
  36. Shimrod_

    Shimrod_

    Joined:
    Oct 18, 2017
    Posts:
    7
    Hi, sorry if the question has been answered or if I misread the documentation.

    With Touch+, I'm using a combination of rotate (1 finger) / drag (2 fingers) / dolly (pinch). I need to recreate something like Sketchfab's navigation.

    Sadly I have a lot of conflicts between these 3 gestures.
    Drag / Pinch : during a drag, the camera shakes a lot if I slightly (and unvoluntarely) increase/decrease the distance between my fingers.
    Both / rotate : as soon as I "remove" a finger from the screen, the camera rotates, like if it interprets the remaining finger as the end of a rotate input.

    Looking into Conflicting Controls, I guess I should deactivate other components while one is active but I don't really see how.

    If useful, I setup my camera this way :
    Camera Pivot : Lean Pitchyaw / Lean Multi Update / Lean Drag Camera
    > MainCamera : Lean Maintain Distance / Lean Multi Pinch

    Thanks for your answer ! (and for the asset, very useful)

    EDIT : also, not really an issue, but tested on a touch screen (Dell P2418HT) and on a Surface Pro, I have to ask for one more finger that it actually requires.
    Multi Update, required finger count : 2
    Drag / Pinch : 3

    EDIT #2: I had a few progress by disabling in MultiPinch the MultiUpdate. I then added LeanLastUp on an empty GO to re-enable it, but it sometimes stays disabled, can't figure what I'm missing.
     
    Last edited: Mar 21, 2022
  37. Tsigaro

    Tsigaro

    Joined:
    Oct 1, 2014
    Posts:
    6
    Hello Darkcoder,

    I've sent you an email yesterday but I didn't know this thread existed sorry.

    I'm trying to understand Lean Touch (I'm very new to Unity) to see if it can fill my needs for a mobile 3D game (top down view) :

    I need to be able to move my player like with an onscreen joystick, swipe to dodge in the swipe direction and tap/double tap for 2 separate actions.
    Also, I need the gestures to be recognized in a specified area of the screen (like a defined UI panel for example) and co-exist on this single area.
    And I would like to define a "swipe length" that is scaled across different screen size, like between phones and tablets.

    From what I understood from your demos, the demos related to what I need are :
    - Swipe : Finger Swipe + Rotation (with Lean Roll) to get angle/direction of swipe
    - Tap : Finger Tap
    - And for movement : Use Lean Touch Events ? FingerUpdate if I remember correctly.

    Do you think I can achieve what I want with Lean Touch ? Do I need Lean Touch+ ?
    Also, if I use FingerUpdate for movement, how can I do to not interfere with your Finger Swipe script ?

    Sorry for eventual dumb question but I'm a little bit lost.

    Thank you
     
  38. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    343
    Good day sir. I'm setting up tooltips and was wondering, does LeanTooltipData support rich text? Thanks.

    EDIT: I spoke too soon and should have just tested it. I replaced the text component with a TextMesh Pro UGUI component and all the TMP tags work just fine.
     
    Last edited: Mar 23, 2022
    Darkcoder likes this.
  39. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    LeanTouch+ has the LeanManualRotate component ("LeanTouch+/Examples/Drag/02 Turn 2D demo" scene), which has the RotateAxesToCamera setting, which should do what you want.

    The LeanGestureToggle component can be used to enable/disable components based on which gesture (e.g. drag, pinch, twist) you perform first. This can be used to prevent conflicts like this.

    I'll put it on my to-do list to get a touchscreen monitor so I can actually test this myself.


    I'll answer you via email.
     
  40. Shimrod_

    Shimrod_

    Joined:
    Oct 18, 2017
    Posts:
    7
    Thanks for your answer. :)

    I don't get if LeanGestureToggle is intended to solve the conflict between a 1-finger and a 2-fingers gesture, which is my main problem.
    I now have a working flow with :
    1) 2-fingers gesture disables 1-finger gesture (MultiUpdate linked to PitchYaw).
    2) LeanLastUp reactivates this MultiUpdate.

    Still, LeanLastup doesn't always does its job, meaning that I randomly have to touch twice the screen before being able to rotate the view. (Maybe is it related to a touchscreen and Windows ?)
    And to disable the 1-finger gesture, I'm using the OnFingers event, which is missing in the Drag component. So I replaced this one by ManualTranslate + a 2nd MultiUpdate (CameraPivot - TranslateAB), which works quite well.
     
  41. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    It sounds like you want to combine Camera scenes 06 and 09 (see attached). This uses Use/RequiredFingerCount to prevent conflicts between 1 and 2 fingers.

    I just tested this on mobile and it seems to work, but as I don't know a touschscreen monitor (yet), I don't know what Data is sending for the fingers. You may have to disable the LeanTouch component's UseMouse and UseHover settings and/or untick DisableMouseEmulation.
     

    Attached Files:

  42. Shimrod_

    Shimrod_

    Joined:
    Oct 18, 2017
    Posts:
    7
    Hi,
    thanks for taking the time, that was my initial setup. You are right, I completely missed this point and disabling Hover and Mouse solved all the conflicts, so I could revert to this simpler setup.
    Please note that with touchscreens, the -42 finger is still active in builds.
    Thanks again ! :)
     
    Darkcoder likes this.
  43. AustinDrozin

    AustinDrozin

    Joined:
    Jun 8, 2016
    Posts:
    43
    FOR LEAN POOL

    Hello! I'm running into "You're attempting to despawn a gameObject that wasn't spawned from a pool (or the pool was destroyed).", but I honestly don't know what is different. I've used this asset a ton and never run into this.

    I'm spawning a prefab that was a parameter in the inspector.

    Then later, from a different script, I'm despawning that gameobject that was spawned using LeanPool. Get this error.

    It's a pretty straightforward use of this asset so I'm not sure what's goin on.

    LeanPool.Spawn(_so.prefab, transform.position, transform.rotation);


    LeanPool.Despawn(obj);


    _so is a scriptableObject. I also tried it with just a GameObject variable so it was in the inspector.

    Debugger doesn't do anything.
     
    Last edited: Mar 29, 2022
  44. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    It's likely you're despawning the clone multiple times.
     
  45. AustinDrozin

    AustinDrozin

    Joined:
    Jun 8, 2016
    Posts:
    43
    wow... thank you. the one thing I didn't check for. easy mistake.
     
    Darkcoder likes this.
  46. EpicMcDude

    EpicMcDude

    Joined:
    Apr 15, 2013
    Posts:
    117
    Hi Carlos,

    I'm making some custom actions for Playmaker for Lean Pool, and I'm currently trying to get a Despawn Self action. I'm still learning C#, I'm doing these custom actions to learn code.

    I'm using the Lean.Pool namespace and I have a private variable that references the LeanGameObjectPool called poolObj, but the below code doesn't work. Do I need a specific reference to the game object with the LeanGameObjectPool component?
    Is it possible to despawn the spawned object by itself?

    Code (CSharp):
    1. public override void OnEnter()
    2.         {
    3.              poolObj.Despawn(Owner, Delay.Value);
    4.  
    5.              Finish();
    6.         }
    Thank you
     
  47. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    What do you mean it doesn't work? You get an error?
     
  48. EpicMcDude

    EpicMcDude

    Joined:
    Apr 15, 2013
    Posts:
    117
    N̶o̶ ̶e̶r̶r̶o̶r̶,̶ ̶i̶t̶ ̶j̶u̶s̶t̶ ̶d̶o̶e̶s̶n̶'̶t̶ ̶d̶e̶s̶p̶a̶w̶n̶ ̶t̶h̶e̶ ̶o̶b̶j̶e̶c̶t̶,̶ ̶d̶o̶e̶s̶ ̶n̶o̶t̶h̶i̶n̶g̶.̶

    Nevermind, it does throw a NullReferenceException error.

    This is how my action looks like -

    Code (CSharp):
    1.   //[Tooltip("The Game Object with the Lean Game Object Pool component.")]
    2.         //[RequiredField]
    3.         //[CheckForComponent(typeof(LeanGameObjectPool))]
    4.         //public FsmOwnerDefault Pooler;
    5.         [HasFloatSlider(0, 10)]
    6.         public FsmFloat Delay;
    7.         private LeanGameObjectPool poolObj;
    8.         public override void Reset()
    9.         {
    10.             //Pooler = null;
    11.             Delay = null;
    12.  
    13.         }
    14.  
    15.         // Code that runs on entering the state.
    16.         public override void OnEnter()
    17.         {
    18.             //poolObj = Fsm.GetOwnerDefaultTarget(Pooler).GetComponent<LeanGameObjectPool>();
    19.              poolObj.Despawn(Owner, Delay.Value);
    20.  
    21.              Finish();
    22.         }
    23.     }
    24. }
    If I don't comment out the reference to the object with the LeanGameObjectPool component, this works without any issues. But that means I would have to find the game object with the pool component every time I want to despawn an object that was spawned.

    I'm guessing there's no way for an object to despawn itself without having a direct reference to the game object holding the LeanGameObjectPool component? Since they were spawned by this pool I just thought I wouldn't need to reference it again.
     
    Last edited: Mar 31, 2022
  49. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,404
    If you don't set the poolObj to anything then of course you will get this error. You can just call LeanPool.Despawn(yourClone); and it will automatically find the pool and despawn it. Keep in mind that if your object was spawned using LeanPool.Spawn then it will be added to the LeanPool.Links dictionary, which makes despawning it very fast. However, if you spawned it directly from the pool using LeanGameObjectPool.Spawn, then despawning it using LeanPool.Despawn will be slower, because it has to check each pool to see which one it came from. Or in other words, you should try and pair up LeanPool.Spawn/Despawn and LeanGameObjectPool.Spawn/Despawn calls, without mixing them togeher.
     
    EpicMcDude likes this.
  50. EpicMcDude

    EpicMcDude

    Joined:
    Apr 15, 2013
    Posts:
    117
    Oh god I'm such a noob. Sorry you had to witness this.
    Yeah I just checked my action for spawning and I did write it correctly with LeanPoon.Spawn (not poolObj.Spawn). For some reason I wrote my "despawn self" action referencing the poolObj object, so of course it would throw an NRE error if I didn't assign it to anything.

    The LeanPool.Links.dictionary was what I had in mind when I was writing the action, that's why I was thinking I didn't need to reference it directly, I just wrote the action wrong. I changed it to LeanPoon.Despawn(Owner) and it works.

    Thanks man
     
    Darkcoder likes this.