Search Unity

  1. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Unity MARS Direct Placement Example

Discussion in 'Unity MARS' started by unity_andrewm, Jun 9, 2020.

  1. unity_andrewm

    unity_andrewm

    Unity Technologies

    Joined:
    Jun 25, 2015
    Posts:
    71
    Hey folks,

    We've seen some requests for a direct tap-to-place example with MARS. I've included a package in this thread that adds a Direct Placement template to MARS.

    In the template scene, valid surfaces are highlighted when the cursor is over them.
    Tap to change where on the screen the cursor is aiming, hold to place the object.
    We have 'valid surface' configured to be horizontal surfaces of a minimum size, but you are free to change the conditions to any alignment.
     

    Attached Files:

  2. JohnnyOkami

    JohnnyOkami

    Joined:
    May 22, 2015
    Posts:
    8
    This was much needed and very helpful in moving forward.

    I'm seeing something slightly bizarre that I was hoping you could help clarify:

    When building and running on iPhone/Android, the GameObject starts out well placed on the plane (table), however when going "under" the plane/table the GameObject "seeps" through. Curious if this has something to do with the Proxy Forces that's applied to the plane, or alignment related to the Camera/Player position(?)

    1.png 2.png
     
  3. wickedwaring

    wickedwaring

    Joined:
    Feb 5, 2014
    Posts:
    15
    Hi Andrew,

    Just to clarify, you can only actually see the placement when running on a physical device?

    We cannot run this in the simulator view? and click to place / test / iterate an object in that view?

    Sorry, just trying to work out what I can and cant do with the simulator view.

    Cheers
     
  4. JohnnyOkami

    JohnnyOkami

    Joined:
    May 22, 2015
    Posts:
    8
    I noticed this as well, but in general Simulation View appears wonky..
    However, you should still be able to do iteration from the standard [Scene] and [Game] views.
     
  5. unity_andrewm

    unity_andrewm

    Unity Technologies

    Joined:
    Jun 25, 2015
    Posts:
    71
    You definitely can test in the editor - you need to enter traditional playmode to do so. For reference, anything that is 'application' or interaction logic requires play mode to test. That being said, when you enter playmode your simulation environment and controls will go with you.


    A question for you - did you add forces to the scene? The example template just uses direct transform manipulation.

    I suspect your camera origin is updating (which AR devices often do at runtime) and the placed object isn't moving with it. I'm working on a more elegant solution for that problem. In the meantime, you could keep track of the collider the raycasting script hit, and parent the placed object under it. That would keep it moving with the camera transform update. I can upload an example of that if you need.
     
    wickedwaring and JohnnyOkami like this.
  6. JohnnyOkami

    JohnnyOkami

    Joined:
    May 22, 2015
    Posts:
    8
    Thanks for replying!

    In modifying your template, yesm the two proxies utilized have forces:
    Horizontal Plane & Game object - Snap to Horizontal Surface
    (Also fooled around with Snap to 2D Plane to see if that would change anything, but the results appeared the same)

    I also had a hunch it mighta been something with the camera.. in the Forces segment of MARS’ documentation, one of the examples talks of making another “Player Reference” for proxies to be aligned with rather than the default MARS Proxy User within the MARS session..¯\_(ツ)_/¯

    I’ll attempt coupling the collider and the placed object, but an example would be well received.

    Thanks again for the detailed assistance.
     
    Last edited: Jun 19, 2020
  7. unity_andrewm

    unity_andrewm

    Unity Technologies

    Joined:
    Jun 25, 2015
    Posts:
    71
    If your placed object is using forces, you could also turn on 'continuous solve' which should also keep it aligned to any found plane
     
  8. JohnnyOkami

    JohnnyOkami

    Joined:
    May 22, 2015
    Posts:
    8
    Is this more involved that adding
    obj.transform.parent = objectTransform.transfrom;
    within the PlacedObject function?
    I attempted appending that to Raycaster.cs in the Example and it still didn't work.

    Separately, I started fresh with the project adding Forces to the Proxies:
    - Once to ONLY the Object to Place
    - Both to the Object to Place and the Proxy Game Object (ie the Capsule)

    In all instances the alignment still isn't adhering to the plane and "sinking" below a table.

    Feel like i'm running in circles >_<
     
  9. JohnnyOkami

    JohnnyOkami

    Joined:
    May 22, 2015
    Posts:
    8
    @unity_andrewm
    I apologize to bug, but if you could provide an updated streamlined example it would really help.

    Regardless the configuration Direct Placement and the use of Proxy Forces aren't mixing well to function as intended.

    Thank you
     
    FutureSystems and Blarp like this.
  10. unity_andrewm

    unity_andrewm

    Unity Technologies

    Joined:
    Jun 25, 2015
    Posts:
    71
    Hi Johnny,

    Try this version of the direct placement script - it handles the reparenting and should keep the position locked.
     

    Attached Files:

  11. FutureSystems

    FutureSystems

    Joined:
    Aug 21, 2019
    Posts:
    19
    I have just tried the direct placement template and I can only get the axes to show. It does not place my objects when I click the cursor in the Game View or Device View. Any idea why that is?
    upload_2020-7-9_22-57-35.png
    Also Is there any change that the direct placement could include scaling and rotation of the object while placing it? Or could you please give me some hints on how I could code that please?
     
    Last edited: Jul 9, 2020
  12. FutureSystems

    FutureSystems

    Joined:
    Aug 21, 2019
    Posts:
    19
    Any ideas?
     
  13. unity_andrewm

    unity_andrewm

    Unity Technologies

    Joined:
    Jun 25, 2015
    Posts:
    71
    Tapping positions the cursor, long-pressing will place the object.

    We may include more advanced placement options like scaling/rotation, but have not decided yet.

    The direct placement script can be modified to support these parameters. I would recommend changing the m_CursorTransform variable which is what the placed object uses as its placed position/rotation.
     
    FutureSystems likes this.
  14. JohnnyOkami

    JohnnyOkami

    Joined:
    May 22, 2015
    Posts:
    8
    Apologize its taken forever to get back to you. Focused on other things before circling back.

    I hate to make this issue seem more trivial than it may be, but even with your modified Raycaster.cs code for direct placement I'm still having the same issue where the object sinks below the plane it is placed upon (ie a desk) when built to a phone. To clarify the raycasting itself seems fine as the object is atop the detected plane, but upon moving the camera down, so too goes the object without locking.

    Additional Notes: "Screen Mode" is somewhat confusing, it would seem more relevant to have it Disabled (meaning that it utilizes parent transform events), but building and testing this too yields the same result when on mobile devices.

    I'm still actively following this thread and am committed to helping you however I can. Perhaps there's something I still don't completely understand.

    Thanks for all the efforts.
     
  15. theotherbedford

    theotherbedford

    Joined:
    Jul 2, 2020
    Posts:
    2
    Is there any more development in this area of direct placement being implemented in the near future?
     
  16. theotherbedford

    theotherbedford

    Joined:
    Jul 2, 2020
    Posts:
    2
    Is there any improvement being released for Direct Placement?
     
  17. ntvd1207

    ntvd1207

    Joined:
    Dec 16, 2018
    Posts:
    12
    the raycaster script has a ton of errors on load. What do I do about that? Does the example need to be modified?
     
  18. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    146
    Hey there, @ntvd1207! I'm sorry to hear that you're having trouble.

    I just tried the example on the latest version of MARS and I only see one compile error, which was fixed by clicking "Okay, I made a backup" on the Script API updater dialog. There's one reference to `MarsRuntimeUtils` which needs a `using Unity.MARS.MARSUtils;` at the top of the file.

    I've updated the package with this fix, so hopefully that clears up what you were seeing. However, if you're seeing "a ton" of errors then I wonder if there's something else going wrong. What version of MARS are you using? Did you do anything to the `Assets/MARS/Content` folder which is automatically populated when you first import MARS?

    Hope this helps!
     

    Attached Files:

  19. Lisasz

    Lisasz

    Joined:
    Dec 10, 2015
    Posts:
    2
    This template is working fine for me in Unity (MARS simulation), but not when built on an iPhone 6s running iOS 14.2. I'm not seeing any Flat Surface PlacementTargets with the blue DirectPlacementHighlight, even as the Planes Visualizer is picking up plenty of planes that appear to satisfy the proxy conditions. (I haven't had trouble with other MARS builds to this phone - no issues with basic proxy planes or image markers.) Any suggestions?
     
unityunity