Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

[RELEASED] Snap-and-Plug: join anything to anything

Discussion in 'Assets and Asset Store' started by a436t4ataf, Sep 15, 2014.

  1. giuoliv

    giuoliv

    Joined:
    Jan 19, 2017
    Posts:
    2
    Hi, thank you so much for the very quick answer, yes I'm using other assets and scripts using 2D physics, so it would be great if you could try to code a 2D add-on to SnP that works with 2D physics too. I will writing an email in few hours.
    Thanks again!
     
  2. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    98
    Hi, Is it works for webGL?
     
  3. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    Yes, I use it on multiple webGL projects at the moment.
     
  4. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    This week I've been working on the new live-debugger that lets me see which modules are active (SAPv3 is much more modular, all done through drag/drop in the UnityEditor (or by single line of code in scripts)) and how they're interacting with each other, and why snapping is/isn't happening.

     
  5. wechat_os_Qy0128_6hl32gJ9TvurFeYlus

    wechat_os_Qy0128_6hl32gJ9TvurFeYlus

    Joined:
    Jul 15, 2020
    Posts:
    10
  6. wechat_os_Qy0128_6hl32gJ9TvurFeYlus

    wechat_os_Qy0128_6hl32gJ9TvurFeYlus

    Joined:
    Jul 15, 2020
    Posts:
    10
    just but iy.

    This is ONE EXAMPLE of how you can implement in-game snapping with a 3D preview.
    *
    ****************************************************************************************
    * As of SnapAndPlug version 2.3.0, THIS CLASS IS NO LONGER NEEDED (there is a better
    * built-in snapping solution provided by SnP v2.3 onwards).
    * Look at "DragDropAction3D" and the documentation / examples for it.
    ****************************************************************************************

    i can't find any docmentation and examples for this DragDropAction3D.

    please help.
     
  7. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    For questions around DragDropAction3D, email me via the support address, or on discord - https://discord.gg/Pstd6Nh

    - I am still rewriting and improving that class, I have a much better version for SAPv3 (not released yet, still testing and debugging it!).

    If you tell me about your use-case, I can talk you through the best way to use DragDropAction3D and make sure that it will be easy for you to use the new version when that is live.
     
  8. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    Yes, that is exactly the kind of game it is made for.

    However: the current version (v2) is low-level and requires you to do a lot of the work - it includes examples of a few different ways you can setup the in-game building.

    ...but the new version (v3, not released yet) includes much more pre-made systems so that in-game building works with less work from you.
     
  9. wechat_os_Qy0128_6hl32gJ9TvurFeYlus

    wechat_os_Qy0128_6hl32gJ9TvurFeYlus

    Joined:
    Jul 15, 2020
    Posts:
    10
    O, great! i think your addon is good one, but just lack of some good demos.
    can you make some kind of KSP sytle demo in the next version?
    when the next verson will come out?
    thanks for the quick reply. good luck!
     
  10. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    KSP had a team of 30 working on it, so it's a high standard to try and reach :).

    Before COVID-19, I was aiming to release v3 in June/July. Now that's more likely to be August/September - it is difficult to be certain, everything has changed so much (job, revenue/income, family and friends sick or worse, etc).

    But I'm pushing forwards to try and get it finished as soon as I can.
     
  11. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    (also, note: anyone who has issues with the current version, feel free to email me or message me on Discord, and I'll try to help. Sometimes I can send you custom fixes, if it's something small - but bigger things have to wait for v3 I'm afraid)
     
  12. Rackminster

    Rackminster

    Joined:
    Jun 12, 2020
    Posts:
    8
    I'm in the early stages of making a top-down space combat game and it hit me this morning that the concept I was working towards would be much easier - and I believe get players more invested - if a player can custom-design their own ship.

    So far all of the elements of my prototype are 2D (because I started with flat .PNG sprites) but it's not like I have hundreds of assets or scripts to correct. My ships and bullets move using Rigidbody2D.AddForce, but I think I can switch it over to 3D without breaking anything. Correct me if I'm wrong, but it sounds like this only works for 3D physics currently?

    The core of my question, though, is if this lets the programmer (or player) basically create a single object out of the components, and if it's easy to get the components to pool their "stats" into one pile.

    Ex: I might design an Engine component that adds X thrust when used, has Y weight (for Gravity calcs), and uses Z power. There would be stats like that on each part - so if I added two similar engines, I'd have 2X thrust. I'd want players to be able to snap together their own prefab parts and get the stats to all pool together. If it all comes together under a parent object, I can pull out the stats that way easily enough.

    If this is fully capable of that, even with some work, I'll probably grab it. It looks incredibly useful and versatile.
     
  13. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    It's 1am here so I'm heading to bed :) but briefly ...

    Sounds good.

    Yes, I've done most of the work to make it work with 2D also in the next version, and I've got halfway through retro-fitting 2D physics into the current version - but it requires a lot of code changes.

    I did this in one of my early experiments using the build from 2017, so it's definitely possible.

    Briefly:
    1. The current version (v2.x) has a few utility methods that help with this - SnapPiece has a method "GetAllIndirectlyConnectedPieces" which gets you all the other things that are snapped to this - or snapped to things that are snapped to things .... that are snapped to this (you get the idea)
    2. I used that method to take ANY piece, and get a list of all its co-snapped pieces, and then just summed up things like "power added", "power used" etc, and used it to make vehicles that need engines + wheels + fuel cells.
    3. There's also a method that permanently dissolves all the connections, but makes them into a single big GameObject, which I used for making an in-game-prefabbing system (not Unity prefabs, but instead works in-game). I'm planning to compeltely rewrite that for v3!
    FYI here's a copy/paste of the code for 3 above, showing you it's pretty simple to write things like this using the API calls:

    Code (CSharp):
    1.  
    2.  
    3. // this is in the class SnapGroup (which is auto-created as soon as you snap 2-or-more pieces together)
    4.  
    5. public void BakeIntoSinglePiece()
    6.         {
    7.             foreach (var p in GetComponentsInChildren<SnapPiece>())
    8.             {
    9.                 p.DisconnectAllSockets();
    10.                 foreach (var s in p.sockets)
    11.                 {
    12.                     DestroyImmediate (s.gameObject);
    13.                 }
    14.                 DestroyImmediate (p._FindObjectThatHoldsAllSockets ()); // remove the Sockets container-object
    15.                 DestroyImmediate (p); // remove the redundant child piece
    16.             }
    17.  
    18.             /**
    19.              * Replace the group with a top-level single snap-piece */
    20.             gameObject.AddComponent<SnapPiece> ();
    21.             DestroyImmediate (this);
    22.         }
    Go for it. If you have problems, email the support address (support at snapandplug.com) or try the Discord channel I recently created (link a couple of posts above).

    NB: I'm only doing urgent and emergency patches for the current version right now - I'm mostly focussed on getting the new v3 working and live instead.
     
  14. Rackminster

    Rackminster

    Joined:
    Jun 12, 2020
    Posts:
    8
    That's very cool. It sounds like this covers exactly what I want to accomplish.

    I appreciate your reply and will very likely be making the purchase today. I'll let you know if I have any issues or questions. :)
     
  15. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    More tests/upgrades of v3:



    I upgraded a 3-year old project of mine from SAPv2 to SAPv3. I found lots of small places where it could be easier to setup/use, and some ideas for new features - here's SAP running simultaneously on two cameras, but with unique "snap universes" for each camera, so that objects in one cam don't affect the other.

    This also enables features like the "overlay mode" seen here, where it's easy to use SAP in an overlay camera, without affecting your main game / main scene data (you can then save the data from the overlay, use it to modify your gameobjects in your main scene).
     
    DavidLe360 likes this.
  16. Rackminster

    Rackminster

    Joined:
    Jun 12, 2020
    Posts:
    8
    I got this today and plugged it into my project. In under an hour I had created some new parts and attached scripts to them to get them working together as a complete object - but I ran into an issue.

    My movement script includes both an AddForce to change the direction of the Rigidbody and a transform.rotate to follow the position of the mouse cursor while strafing.

    Because the engine part is generating the Force for movement, it's accounting for the mass of all attached objects. That's perfect since I want bulkier ships to move slower. The problem comes in when I rotate the transform to follow my mouse cursor and apply any left/right force. The mass of the non-engine components is throwing off the equilibrium and I end up with a wild uncontrolled spin. When I set these parts to zero mass, the strafe/mouse follow returns to perfect working order and all attached parts rotate with the engines.

    Is there a recommended method for using something like AddForce to strafe and be able to follow a mouse cursor without having to set all other parts to a mass of zero? The test was done with 2-3 small parts with Fixed sockets. If you feel this isn't something the Snap-and-Plug (the forum wouldn't let me make this post with abbreviated S a P (no spaces), said it was offensive or spamming) module is doing but rather some other conflict with Unity's physics engine, I can keep hunting for answers.

    Aside from this hiccup, it's a really nice utility and once I get this ironed out, it should accelerate my project greatly.

    My movement script is below:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Space3DStrafeMove : MonoBehaviour
    5.  
    6. {
    7.     //movement variables
    8.     public float v_speed = 3;              
    9.     public float v_rotationSpeed = 60f;
    10.  
    11.     //private calculation variables
    12.     private Vector3 v_lookDirection;
    13.     private float v_lookAngle;
    14.     Quaternion v_targetRotation;
    15.  
    16.     //object variables
    17.     private Rigidbody v_rigidBody;
    18.  
    19.     // Use this for initialization
    20.     void Start()
    21.     {
    22.         //store a reference to the attached Rigidbody object
    23.         v_rigidBody = GetComponent<Rigidbody>();
    24.  
    25.     }
    26.  
    27.     //FixedUpdate is called at a fixed interval and is independent of frame rate. Put physics code here.
    28.     void FixedUpdate()
    29.     {
    30.         //Store the current horizontal input in the float moveHorizontal.
    31.         float v_moveHorizontal = Input.GetAxis ("Horizontal");
    32.  
    33.         //Store the current vertical input in the float moveVertical.
    34.         float v_moveVertical = Input.GetAxis ("Vertical");
    35.  
    36.         //Transform cursor position to world coordinates
    37.         Vector3 v_mousePosition = Input.mousePosition;
    38.  
    39.         //strafe toggle, ship remains oriented towards mouse cursor
    40.         if (Input.GetKey(KeyCode.LeftShift))
    41.         {
    42.             //set v_rotationSpeed
    43.             float v_rotationSpeed = 60f;
    44.  
    45.             //Establish the mouse position in the camera relative to the position of the ship
    46.             v_lookDirection = Camera.main.ScreenToWorldPoint(v_mousePosition) - transform.position;
    47.  
    48.             //Create an angle that the ship will need to move towards in order to look at the mouse cursor
    49.             v_lookAngle = Mathf.Atan2(v_lookDirection.y, v_lookDirection.x) * Mathf.Rad2Deg;
    50.  
    51.             //Use the two store floats to create a new Vector2 variable movement.
    52.             Vector3 v_movement = new Vector3 (v_moveHorizontal, v_moveVertical);
    53.  
    54.             //Call the AddForce function of Rigidbody supplying movement multiplied by speed to move player
    55.             v_rigidBody.AddRelativeForce(v_movement * v_speed);
    56.  
    57.             //Update our target rotation to move towards.
    58.             v_targetRotation = Quaternion.Euler(0f, 0f, v_lookAngle-90f);
    59.            
    60.             //gradually rotates the ship towards the mouse pointer
    61.             transform.rotation = Quaternion.RotateTowards(transform.rotation, v_targetRotation, v_rotationSpeed * Time.fixedDeltaTime);
    62.         }
    63.  
    64.         //this creates smooth up and down, rotate left and right, fly in direction the transform is pointing
    65.         if (!Input.GetKey(KeyCode.LeftShift))
    66.         {
    67.             //Use the two store floats to create a new Vector3 variable movement.
    68.             Vector3 v_movement = new Vector3(0, v_moveVertical);
    69.  
    70.             //rotate the transform on the horizontal axis, uncontrolled speed though
    71.             transform.Rotate(0, 0, -v_moveHorizontal);
    72.  
    73.             //apply force relative to the existing heading of the ship
    74.             v_rigidBody.AddRelativeForce(v_movement * v_speed);
    75.         }
    76.     }
    77. }
     
  17. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    That's kind of cool :) although it's annoying.

    First question: which kind of SnapJoint are you using here? (basically: are you using the physics-joints or the non-physics joints?). I'm assuming you're using the physics-joints from what you say, which causes Unity to model each part of the spaceship as a separate physics item, and keep simulating all of them indepdnently (with their mass etc).

    (if NOT ... then probably what's happening isn't center-of-mass, it's instead center-of-GameObject-group - by default, SnP automatically recenters the Unity local transform of a group of snapped objects after each snap, so that they're easier to work with in the editor and in code. This is optional, you can disable it in the snap methods by passing in a special parameter - although I'm not sure if that feature was added early in v3 or late in v2, I'm pretty sure it's in v2)

    If they're physics joints, then ... I'd consider reducing the masses of all of them to nearly-zero, and increasing the mass of the central one to the sum of what the masses should be.

    OR ... ask unity where the center-of-mass is, and apply the AddForce at that point - off the top of my head: there's a varient of the Unity API method that lets you specify the exact point in 3D where you want the force/impulse/whatever applied (which is very useful for cases like this)
     
  18. Rackminster

    Rackminster

    Joined:
    Jun 12, 2020
    Posts:
    8
    I tried Universal, but the parts split up as soon as I started moving, so I tried Chassis, which also fell apart once I hit play and started moving - then I switched to PhysicsFixed and it worked as expected, if not a little more swirly than aniticpated.

    It sounds like finding the center of mass will maybe be the right course of action for me and work from there instead of from the engine. If/when I get the answer I'll post it back here for others who may need it down the road.

    You mention v3 - is that still somewhere down the road, and will folks who have the 2.3 version be upgraded?
     
  19. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    You can do this using Universal joints, but it would require that you remove/disable any RigidBody components you've added to your snappable pieces (by default there's no RB on new SnapPiece objects, so Universal works out-of-the-box - but once you start adding RB's to things, you prevent that from working. I will try to add some detection for this to v3 and display a warning - it's not obvious unless you're already experienced with Unity's Physics system).

    So e.g. what I do in my VR projects is to remove all the RB's in the callback for "something snapped to something".

    But it depends how you want the object to behave. Using physics joints means Unity will break it apart when it hits a wall hard enough / dropped from a high height. Using non-physics (eg Universal) joints means Unity will treat the sub-objects as permanently attached, and they'll never break off. Depends what kind of gameplay you want!

    (you can still break Universal joints, it's just that you'd have to write your own logic for that. E.g. write some code that breaks-off or destroys specific pieces when a threshold is met)

    Here's the Unity method to choose where to apply a force: https://docs.unity3d.com/ScriptReference/Rigidbody.AddForceAtPosition.html

    ...and I think you would want to apply that at the AVERAGE of all the centers-of-mass of all your rigidbodies. Something like:

    SnapGroup group = ... your snapgroup that is the whole object, auto-created
    Vector3 totalCOM;
    int numAdded = 0;
    foreach( var rb in group.GetComponentsInChildren<RigidBody>() )
    {
    totalCOM += rb.centerOfMass;
    numAdded++;
    }
    Vector3 averageCoM = totalCOM / (float)numAdded;

    then apply your AddForce through that point...

    I'm trying to get v3 finished ASAP. There will be multiple upgrade options - I'm adding a lot of new features (e.g. VR) that not everyone will want/need, so I'm trying to keep the upgrade cost low by making some of the upgrades optional -- I want to use the new Bundles system that Unity just added so that you can do a cheap upgrade for the basics, or also get expansions that add major features.

    ...but I'm going to get it finished first, then look at what I have and what I can do with Unity's bundling / discounts system.
     
  20. Rackminster

    Rackminster

    Joined:
    Jun 12, 2020
    Posts:
    8
    I appreciate your time. I'm still pretty new with Unity, having logged maybe a total of 120 hours over 45 days.

    Before I continue, I want to add that the choices I've made have been best guesses without any real informed knowledge of the total capability of Unity. Essentially, whatever Google turned up as a potential method to achieve my goal was what I tried to do. This is why I'm using the physics engine and AddForce to move my ship. The combination provided me the best representation of Newtonian movement in space without having to rely on trying to constantly speed up and slow down a transform. There may be a way to achieve simulated Newtonian movement with a script that relies on the transform so I can stop fighting with Rigidbodies, but I didn't find it while I was looking. Rigidbodies also seemed to work for the concept of having things ram each other and impart force when they collide, but again, maybe it can be scripted with Transforms and I simply haven't found it yet.

    Based on my limited scope of knowledge and by what you're saying, it looks to my like my best course of action is to forge ahead with the PhysicsFixed sockets so I can maintain the mass of all my combined Rigidbodies and then find the center of mass and AddForceAtPosition. I'll just need to be careful that things don't slam together so hard that they knock parts off each other. I don't want ships to fall apart until they're destroyed, at which time I'd break some (if not all) of the sockets so the parts can move freely away from each other.

    Universal sockets sound much easier to work with, but not if I want to utilize the physics engine for movement (which requires a Rigidbody).

    Another quick question: What update point does the Snap-and-Plug routine use? My ship was moving using FixedUpdate, but that resulted in a "bumping" motion between parts. When I changed over to Update instead, the motion seemed to smooth out. I'm assuming it's either an Update or LateUpdate?

    I didn't follow this entirely. It sounds like you're starting with Rigidbodies, but then clearing them out of anything that's been snapped together using a script?
     
  21. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    If you want programmatic / scripted control of when things break - better to use non-phsysics joints so that it's under your explicit control (although you CAN also make physics joints unbreakable - after they've snapped together, SnP will auto-create a Unity-physics "Joint" component and you can set its break-apart threshold to something insanely high, making it impossible to break).

    I'd either do:

    1. non-phsysics joints
    2. When things snap-together, SnP auto-creates a SnapGroup and puts them all as children for it.
    3. ... when that happens, have your script attach a RigidBody to the SnapGroup directly. Now Unity will treat the combined thing as one big solid object.
    4. When you want destrcution, pick the piees you want to snap off, and write code that calls DisconnectAllSockets on them ... and THEN calls AddComponent<RigidBody>. Now Unity will treat the split-off object/snappiece as a separate physics object, and it will fall away - or you can additionlly cal .AddForce on the newly-split object, and explosively fling it away :)

    or:

    1. physics joints
    2. Each time you snap more things together / add to the SnapGroup, make sure you recalculate the total center-of-mass (using the averaging code I wrote in previous post), and apply your AddForce at that point.
    3. ...if things break too easily, modify the unity-joints to have a very high break threshold (you can actually pre-set this data inside the SnP physics joint. It's designed for this: you tell it what parameters you want the unity-joint to have after snapping, and it copies them across at snap-time).

    NB: the SnapJoint objects in Unity are a special Unity-object that if you change one copy it changes all copies. So in most cases you want to create a new instance and modify that rather than modify the ones pre-made for you (both will work, but i's cleaner to make a new isntance).

    e.g. in project window, right-click, "Create" and select whichever type of physics joint you want ... then give it a meaningful name, e.g. "BigShipJoint" - and set its threshold super high. Any snappieces that use that drag/dropped joint will be unbreakable. But now you can do the same and name a new one "FragileShipJoint", set the threshold low, and any snappieces that use that will be liable to fall apart easily - and you can mix and match the different snappieces in a single object.
     
  22. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    It doesn't. What you're seeing is entirely Unity's physics rules (which are simple but take a while to memorise - I recommend finding some tutorials on FixedUpdate vs Update, and especiaally tutorials on animating/moving objects using them - it's worth understanding the details of what works here and what doesn't, because you'll use it in every Unity game you ever write).

    In Unity, it's illegal (slight simplification, but effectively true) to use ANY physics methods except in FixedUpdate, and it's illegal to use ANY transform methods except in Update.

    I could only guess - this is unrelated to SnP, and there are lots of things you could be doing that would cause these differences (hence the recommendation to read-up on FixedUpdate and moving things in Unity).

    Yes, exactly. In the callback for "something snapped to something" you can simply call "Destroy( something.GetComponent<RigidBody>() )" - but make sure you call it on the small piece that was moving, not the peice it snapped on-to (the first time you snap, it won't matter, but as soon as the second item is a SnapGroup full of already-snapped pieces ... you don't want to remove the RB from that any more! That's the RB you artifically added)

    NB: I'm assuming you're using DragDropAction3D to do the in-game snapping - the callbacks for that are sent to the IDragActionSource instance that you passed-in to "StartDrag", and there's two of them: one that tells you a snap is about to happen, and the other that tells you the snap definitely happened.

    However if those are the only two you have available, then writing the code for this is a little annoying, because you need to keep track of whether the snap went ahead or was cancelled by the player. In v3 I've added a lot more callbacks, so there's one that tells you whether the drop was completed or cancelled.

    :(. I'm using the alpha builds for SnPv3 on all my projects at the moment, so I'd forgotten that the new callbacks don't exist in the old version. If you find it too difficult, I can try to make a one-off build with the new callback added, and email it to you - but my local copy of v2 has some other one-off changes I made for other people, so it might not work first time.
     
  23. Rackminster

    Rackminster

    Joined:
    Jun 12, 2020
    Posts:
    8
    I have time to get back into this and am exploring the options you offered that should with with Snap-and-Plug and think the first - managing the SnapGroup by adding a Ridigbody - seems the cleanest.

    The InGame Snapping Demo worked great after I dropped the Standard Asset prefab free camera in there.

    When I open the the CarBuilder scene and click "Run" it loads as a basically blank landscape without the menu popping up or terrain coloring appearing. Unity throws the following notifications and an error at me:

    Notification 1:
    SnP: after internal force-reload of data, is saved instance still null ? False ... asset path = Assets/Plugins/SnapAndPlug/Editor/SnapAndPlug-settings.asset
    UnityEngine.Debug:Log(Object)
    SnapAndPlugEditorScripts.EditorSettings:_LoadOrCreateNewInstance()
    SnapAndPlugEditorScripts.EditorSettings:_SetSharedInstanceIfNull()
    SnapAndPlugEditorScripts.EditorSettings:RunOncePerReload()
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

    Notification 2:
    Info: Unity is running an Editor script in Play mode; we CANNOT safely upgrade now, must skip the upgrade until you're out of Play mode.
    UnityEngine.Debug:Log(Object)
    SnapAndPlugEditorScripts.EditorSettings:_LoadOrCreateNewInstance()
    SnapAndPlugEditorScripts.EditorSettings:_SetSharedInstanceIfNull()
    SnapAndPlugEditorScripts.EditorSettings:RunOncePerReload()
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

    Notification 3:
    [SnP] SnapGlobalSettings: ...auto-loading complete, SnP version is now: 2.3p3 files are in folder: Plugins/SnapAndPlug/Editor/SnapAndPlug-settings.asset
    UnityEngine.Debug:Log(Object)
    SnapAndPlugEditorScripts.EditorSettings:RunOncePerReload()
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

    Error:
    InvalidOperationException: This cannot be used during play mode.
    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty (UnityEngine.SceneManagement.Scene scene) (at <a20a50bbfaff4193bf6ba6b262f9a71f>:0)
    UnityEditor.EditorApplication.MarkSceneDirty () (at <a20a50bbfaff4193bf6ba6b262f9a71f>:0)
    SnapAndPlugEditorScripts.EditorSettings.UpgradeScene (SnapAndPlug.SnapAndPlugScene sceneData, SnapAndPlug.Version vTo) (at <69155796fb5e43e78057e5f34019b769>:0)
    SnapAndPlugEditorScripts.EditorSettings._CheckUpgradeAfterSceneChanged_WorkaroundUnityEditorChangesSceneButDataIsInvalid () (at <69155796fb5e43e78057e5f34019b769>:0)
    UnityEditor.EditorApplication.Internal_CallDelayFunctions () (at <a20a50bbfaff4193bf6ba6b262f9a71f>:0)

    *Edit: Well, that's no fun. After adding an object to the scene and adding the ManageRigidBodies script in it (mimicking the Car demo, so I could start working on the physics of moving a snapped-together body), my project imploded and Unity crashes every time I run it. Trying to delete cache/metadata/scriptassembler files/folders doesn't restore it when Unity rebuilds them.

    Not casting any fault with the SnapAndPlug asset; it could have easily been unfortunate timing... and since I was basically back to rebuilding from scratch to accommodate this, I didn't really lose much work as my scripts for movement and object interaction are all still intact in the Assets folder of the project. I didn't have a backup copy of the project to fall back on and will henceforth establish a backup protocol before using Unity.
     
    Last edited: Aug 2, 2020
  24. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    The CarBuilder demo is one of the oldest ones - writte in 2016, I think? - and is only really for people that want to write their own fully-custom in-game snapping - it requires a lot of scripting (you can use the scripts from the demo itself) but it's much much better to use the InGameSnapping demo and its DragDropAction3D.

    The notifications are fine, and the error shouldn't have any negative effect (it's a new bug Unity created by changing the way they load the Editor, and I have to rewrite the code to workaround Unity's changes - I've already done this for v3, but I don't plan to rewrite v2 for it, it should be something that only happens once or twice and you won't see it again).
     
  25. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    This *definitely* shouldn't happen. It depends what you mean by "crash". My first guess would be that you wrote some code somewhere that has an infinite loop - that's a known bug in the UnityEditor (for 15 years now!). Or that you're running 2020.1 (which was only released 2 weeks ago and inevitably breaks a lot of existing projects). But these would each have different symptoms.

    FYI: Deleting cache/etc folders is unlikely to workaround Unity bugs in 2020 - it used to be valuable 5+ years ago, but the bugs that were triggered by them are almost all (99% or more) fixed in Unity by now.

    Also NB: when the editor does crash, Unity stores logfiles ("Editor.log") on your machine - if you look in the online docs for Unity you can find the location (it's different for every OS and even on different versions of Unity - they keep moving it around). That file has eerything that Unity printed to the console log AND a lot of extra internal Unity info, and usually can tell you what went wrong to cause an Editor crash.

    TL;DR: editor-crashes are very rare in Unity today and it's probably something worth reporting to Unity if you can track it down a little.
     
  26. dasbin

    dasbin

    Joined:
    Jan 14, 2012
    Posts:
    261
    I'm looking at getting this asset for my 2D game where physics objects need to snap together when they get close.

    Couple questions:

    1) Looking at the documentation, it looks like it should be simple to add 2D physics joint support by extending SnapJoint and just add a 2D joint inside the DidConnectTo callback. Am I missing something here?

    2) Is snapping always instantaneous within a single frame? I'm kind of hoping for a realtime solution to make things feel "magnetic" where they move towards each other at a finite speed when they get close enough, and then lock in place (the built-in Physics Effectors and Joints unfortunately don't work for this because either the force has to be so high that things jitter/walk into alignment with each other, or too low to align their surfaces properly). I'm guessing your system doesn't have this ability, and that's not the end of the world: my plan in that case would be to use forces until it gets "close enough" and then just snap into place using SAP.

    3) If someone were to purchase version 2 right now, would you have any sort of grace period for upgrading to v3 (which is of course what I would get now if it were available).
     
  27. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    Sadly it's not that simple - physics is woven throughout the asset, and "2d physics" isn't real physics, so it currently doesn't work. v3 will support both, and I'm backporting this to v2 for other users who need 2D physics, but it's taking some time to finish.

    Yes. But it's under your control - it would only require a small amount of scripting to implement your "motion" setup. This is in fact very similar to how the in-game snapping works in v3 - although the snapping is still instant, it keeps track of the "target" snap position and the "initial" and "current" positions (this lets me give realtime feedback to the player about what WILL happen before it happens).

    You could do that in v2 or v3, it would be slightly easier in v3 because of some extra API calls I've added, but fine in either.

    Unity doesn't let me do this directly, but I'd be willing to do something special for a few one-off cases.

    However, I think the best thing for you is for me to finish the v2 backport of 2D physics ASAP, so you can grab v2 and start using it fully, and then you're not dependent on the uncertain timeframe for when v3 is live.
     
  28. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    As part of the v3 update I'm refactoring lots of old code, removing support for Unity versions less than 2018, etc. I've written a custom "project source code browser" to help me view the source and see what I'm working with - here's the kernel of SnapAndPlug v2 (pre-refactor):

    upload_2020-8-30_23-42-53.png

    ...to put it into perspective: to show all the source-files in this UML-diagram style takes 4 more full screens the same size. Quite a lot of code :). Hopefully post-refactoring: less.
     
    tonywalsh likes this.
  29. Chauvinp

    Chauvinp

    Joined:
    Aug 8, 2018
    Posts:
    1
    hello, first thans for your work, all works Good! my question is with the asset "easy save3", i would like to know what you can conseil me for saving an SnapGroup who are instantiaite in game. SnapGroup isn't a prefab and i don't know how i can save it with "easy save 3". Sorry for my english, i'm french, and thanks for your answer.
     
  30. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    Salut. I haven't used Easy Save 3 before, so I don't know how it works - please email me at support @ snapandplug.com and we can discuss in more detail.
     
  31. shastarama

    shastarama

    Joined:
    Jul 31, 2017
    Posts:
    2
    Hello,

    Making a 2d train sandbox. Is it possible to disable the auto rotation?

    Thank you.
     
  32. jouietamse

    jouietamse

    Joined:
    Nov 24, 2018
    Posts:
    2
    Will this work for two moving game object on collision? like enemy and player colliding each other? like the old beta em up grab mechanic?
     
  33. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    In the current live version on asset-store - no.

    In the current alpha build of the next version (v3) - yes.

    I am working on ways to get this to work in the current live version too.
     
  34. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    Yes. Someone used it in an app last year that did something similar (I think it was a private/corporate app - they sent me a video but I haven't seen it online).

    If you try it and have problems - let me know and I'll prioritize fixing it, because that SHOULD work. The only reason it might fail is if there are bugs in Unity's own physics that prevent it working (I am using Unity's physics / PhysX integration to define collision and closeness, so it should be 100% compatible with anything that Unity can do in physics terms).
     
  35. yoiang

    yoiang

    Joined:
    Jun 3, 2019
    Posts:
    6
    Hello! I just purchased the project and it's working great so far in 2020.2.1f! The ingame snapping was a great example to base my work after. I'm excited to see V3, it sounds like it'll be an even bigger pleasure to work with! Will the API change drastically? Should I wait before I fully integrate the current version? Do you have a sense of timeline for the V3 release?
     
    Camagine likes this.
  36. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    TL;DR: there might be some v3 alpha builds soon, but v3 on the asset store probably won't be live until Spring/Summer 2021 at the earliest. This is almost 1 year behind schedule, mostly due to Covid.

    Details:

    v3 is still some way off - there's a few people I tried to make special builds for in summer 2020, a "v2.5" that was half-way between - but the difference between 2 and 3 was too big, and it took too long to try and keep the 2.5 version in sync.

    Additionally: I started a major rewrite of the kernel, because a lot of non-physics code in Unity itself (which we rely on) ... uses Unity physics internally :(. Which would be OK, except: as @dasbin discovered - Unity3D physics is almost completely incompatible with Unity2D projects.

    My last estimate on timelines was:
    - +4 weeks for a complete beta build of v3
    - +2 weeks for finishing replacing all of Unity physics
    - +3-6 weeks for finishing the new UI features and UI integration, and adding the new in-game VR integration

    ... but Covid ruined it :). My paid contracts (that pay my bills!) got cancelled, and I had to take full-time work in autumn 2020.
     
  37. yoiang

    yoiang

    Joined:
    Jun 3, 2019
    Posts:
    6
    @a436t4ataf Thank you for the super comprehensive update! Totally understand, I'm in a very similar boat. Once you're looking for alpha testers I might be able to help out!

    I was also wondering if you could help me with this, I'm having a bit of trouble understanding what I'm doing wrong using DragDropAction3D. I have a GameObject I'm treating very similar to your example's setup, it has a component that has implemented IDragActionSource, using your nice box generator for highlighting on mouse over and out just fine. However when I try to use DragDropAction3D::StartDrag I get this exception and stack:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. SnapAndPlug.DragDropAction3D.GetMouseHitOnObject (UnityEngine.GameObject clickedObject, UnityEngine.RaycastHit& out_hit) (at <3b79fd4e65504e7a84710f35571642a0>:0)
    3. SnapAndPlug.DragDropAction3D.GetWorldPositionOfClickPointOnObject (UnityEngine.GameObject clickedObject) (at <3b79fd4e65504e7a84710f35571642a0>:0)
    4. SnapAndPlug.DragDropAction3D.StartDrag (UnityEngine.GameObject dgo, SnapAndPlug.IDragActionSource optionalSnappable) (at <3b79fd4e65504e7a84710f35571642a0>:0)
    With debugging turned on the output I get is that the snapobject and the dragged are both the same, the same GameObject from above.

    Lemme know if there is anything else I can share that would be helpful!
    Thanks so much for your time!
     
  38. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    Email me on this - support at snapandplug.com - and I'll dig into it a bit more this weekend. If you have a simple mini project you can share that shows the problem I can try debugging it too.
     
  39. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    v3: Unity2D physics integration is now working (finally!) - you can snap 2D objects directly inside Unity's 2D mode, and seamlessly switch back to the standard Unity mode and it switches to 3D snapping.

    I don't know if I can backport this to the current version - I will look into that in the coming days.
     
  40. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    v3 progress ...
    • SnapPiece.sockets now has a non-allocating / no-GC version, which is now used in all internal methods
    • Finished adding new paradigms: SnapPiece.ForEachSocket(), SnapPiece.FindSocket(), SocketFilter -- lets you reduce the code needed to iterate over sockets, find specific sockets, etc by a factor of 4-5x
    • DDA3D is now compatible with VR/AR, as well as legacy mouse input. I haven't tested with Unity's 'new' InputSystem yet but I think it'll work.
    • Added: a modular/replaceable InGameSnappables system
      • Easy to write your own - for mouse, for phone/tablet, for VR.
      • This is the preferred way to add/customise VR support - it lets you add any VR/XR system with minimal code

    There's still a few big challenges to overcome (the biggest one is: how I'm going to provide drag/drop control over the creation of SnapGroups, and the rules for when Groups are created, when they are merged, when they are split, how they're split, etc). This becomes a big problem e.g. for VR, when you can have two hands working at once, and doing different snap-operations in parallel - or conflicting with each other.

    I've got most of this stuff working in a hacky way - I've had a working VR proof-of-concept since last Spring! - but replacing the 2,000 lines of hacky code with something simple and well-designed, that's less buggy and easier for you to extend and customise ... is a lot of work.
     
  41. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298

    Attached Files:

  42. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    v3 progress ...
    • Today I finally got a v3 build working in one of my existing game projects :) - not every feature is working yet, but all the old features and about half of the new ones worked first time
    • In-game snapping is now a lot more confgurable - directly in-editor, without needing any code (and has a few new features, e.g. hold down CTRL to break items out of a group, making it faster/easier to re-arrange whatever you're building)
    • Internal snapping now has 5 more places you can configure it in-editor, without writing code, by drag/dropping different modules into place (I have 1-3 example modules for each configurable item, although you can easily write your own ones)
    • In-game snapping now has full support for mouse/tablet hybrid games, as well as pure mouse games, using Unity's legacy input (I will probably add a module that uses the new Input system too at some point, but this at least guarantees it will work correctly on all versions of Unity, as a fallback)
    • ... + about 30 different tweaks, bugfixes, refactorings
    • ... + about 15 new automated unit tests
    However ... upgrading a project requires lots of small changes, so I think it won't be possible to do an auto-upgrade this time (For the past 6 years (!) I've always provided automatic upgrades internally so that you didn't need to do anything manually, but this time I think I'll have to just provide instructions for what to change - so much has changed that you'll want to go through item by item and make decisions about which new settings/modules to use and where)
     
    tonywalsh likes this.
  43. tonywalsh

    tonywalsh

    Joined:
    Jun 4, 2014
    Posts:
    15
    Hi, picked up this asset today for a prototype project, looks good but I think I'll wait until v3 is available before going too far with v2. Looking forward to it!
     
  44. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    v3 progress...

    In this video:
    • Note how I can not only snap stuff in-game, but I now have direct control of dismantling too
    • e.g. I can pick off just one piece
    • ... or pick off several pieces...
    • ... and whatever I pick off remains stuck together, but separate from the starting piece.
    • Most of this is using new features built-in to v3 (there's about 75 lines of custom code here, which implements "pick all the pieces above the currently mouse-overed piece") - it has dismantling and drag/drop/attach/break built-in.
    • At the very end there's a bug with the previewing system - it snaps correctly, but the preview is wrong position. Still quite a few bugs like that to clean-up before I can launch this :)


    Still a long way to go before this is live! But we're getting close to a new build for testers...
     
    DavidLe360 likes this.
  45. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    v3 update ... I've fixed the last remaining major bug in the v3 codebase!

    I have to do some cleanup, write new / updated docs, etc, ... but I should have a build ready this week, and emails to betatesters should go out before the end of March.
     
    digiross likes this.
  46. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    369
    Look forward to taking it for a spin in V.R
     
  47. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    Anyone who wants to take part in the v3 beta-test, please fill out this form (it contains info to help me prioritize builds for the people who can use it immediately, and prioritize which features I need to have ready next!)

    https://forms.gle/MiNRSViqvKnq3wCe9

    If you plan to create a new project I can get you a build almost immediately - I just need to write some documentation on all the stuff that has changed! If you have a large existing project you need to upgrade - fill out the form so I can start planning how to get you project upgraded, because right now it requires some manual steps.
     
  48. great3889

    great3889

    Joined:
    Apr 9, 2021
    Posts:
    1
    Hi,
    Hope so you are doing fine. I am looking at this plugin it might solve my problem. I am making an an app for pc where i am building a truck. I have basic container of wall for truck now i need to add different equipments to the walls like snapping them on the wall. But i am importing the 3d models at run time. like i need to add an axe to the wall of the truck first i am importing that axe from the directory and than i need to place it. Is it possible to build some thing like this using this plugin. Where i can import multiple equipments place those equipments to the wall. And those equipment should not move through the wall as well as they should not move through the other equipment only should snap to wall.
    Looking forward to you reply.
    Thanks
     
  49. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,298
    Yes, it's possible. However, it might be easy or hard depending on exactly what you are doing.

    When you say "I am importing the 3d models at run time" do you mean:

    a. Your users press an "import" button and then select a .FBX file (or .blend, or etc) on their hard drive, and your app loads the file and then adds it to the app?
    b. You add/create all the 3D models in the UnityEditor, and when someone uses your app they choose from the models you already created?
     
  50. Nevel

    Nevel

    Joined:
    Apr 1, 2014
    Posts:
    2
    could you please share discord link. In asset store it does not working anymore
    I have couple questions:
    1) Is it possible to increase "magnet zone", currently you should bring 2 modules really close to stich them together
    2) Can i connect 2 modules after instantiating (without drag and without using InGameSnappable script)? E.g i spawn 1 cube, then 2 second and stich them.
    3) Is it possible to drag by 2 axis, instead of x,y,z. I can do something like this
    Code (CSharp):
    1. currentDrag.draggedObject.transform.position = new Vector3(currentDrag.draggedObject.transform.position.x, currentDrag.draggedObject.transform.position.y, 0);
    But looks like it does not affect on ghost model representation while dragging.
    4) Is it possible to snap model to ground. E.g. i want place tree on terrain and i want place socket only on lower part of tree without spawning hundret sockets on terrain.

    P.s. Thanks for asset, it's great tool. Answers will be much appreciated!
    Regards
     
    Last edited: May 12, 2021
unityunity