Hello I’ve been playing with the ARcore examples and am struggling to have a working button, the helloAR example where you can place an “andy” model i’ve got a button hooked up to swap between different models however whenever this button is hit it also places a model is there a way to tell ARcore to ignore a certain layer / tag I’m really struggling to see it, any advice would be greatly appreciated : )
It is UI Button and Touch Input 's problem.
solution here:
Hello thanks for the reply, this definitely feels like it could be the issue! but I’m struggling as to how to put this in the Hello AR controller?
Hi @JasonJohn1977 ,
@thantieuhodo91 is right – the issue is that both the UI button and the HelloAR sample both respond to touch input. If you look at HelloARController.cs, around line 132, you’ll see that it performs raycasts looking for a place to put the andyObject anytime there is a touch input. This is a good starting point, but to extend it to support the type of logic you’re describing, you may want to just copy this code into your own component and only perform the hit test on ARCore planes when the a button is not being pressed. So basically wrap that raycast logic in a
if (!IsPointerOverUIObject()) {...}
type of statement.
Cheers,
Tim
Hi @tdmowrer
This fixed my issue, I used the lineif (!EventSystem.current.IsPointerOverGameObject(touch.fingerId)) {...}
thanks so much for your help : )
Hi, I seem to be having the same issue when adding @JasonJohn1977 's code the prefab simply won’t even place. what do you think could be going wrong? For reference here is my code snippet,
if (Session.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit) && doPlace && !EventSystem.current.IsPointerOverGameObject(touch.fingerId))
{
var andyObject = Instantiate(AndyAndroidPrefab, hit.Pose.position, hit.Pose.rotation);
// Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
// world evolves.
var anchor = hit.Trackable.CreateAnchor(hit.Pose);
// Andy should look at the camera but still be flush with the plane.
andyObject.transform.LookAt(FirstPersonCamera.transform);
andyObject.transform.rotation = Quaternion.Euler(0.0f,
andyObject.transform.rotation.eulerAngles.y, andyObject.transform.rotation.z);
// Make Andy model a child of the anchor.
andyObject.transform.parent = anchor.transform;
doPlace = false;
}
Don’t add the condition in above if statement using &&. Just wrap raycast using if(!EventSystem.current.IsPointerOverGameObject(touch.fingerId)){…}
Also check your doPlace var, maybe its always false
Hi, sorry for the dumb question but I’m a complete beginner. I’m trying to create a item menu for a AR scene in Unity. In my scene you can choose between different 3D items in a list and than spawn the corrisponding item when I touch a tracked plane in the app. When I try to spawn a single tipe of 3D object it works (basically like helloAR), but I can’t figure out how to make it work with a list of objects.
Thanks!
Hi,My problem is similar I want to create a button with a list of objects from where to select different objects and put them in the real world. Can someone help with a script or instructions to do that?
@jarod-smith Do I get error with Raycast and doplace?Can you send me all your code?
hallo I have the same question with you, I would like to add a UI bottom as a menu to select the item. I wonder whether your problem has been solved or not, and how did you deal with it?
I recommend you to check out this Udemy course: https://www.udemy.com/create-ar-placement-app-and-full-template-for-photo-app/
I found it extremely interesting and, since I am a beginner, it put me on track to develop more interesting ar apps. It also explains how to create a menu for your ar app and gives you a working solution on wich you can build further.
The teacher Satwant Singh also has an interesting youtube channel where he uploads more videos on ar
So, the same question, I tried to implement it in ARCore v1.13.0 and I changed the line:
if (!EventSystem.current.IsPointerOverGameObject(gesture.FingerId))
because touch.fingerId changed for gesture.FingerId, but this doesn’t work properly, am I missing something?
namespace GoogleARCore.Examples.ObjectManipulation
{
using GoogleARCore;
using UnityEngine;
using UnityEngine.EventSystems;
/// <summary>
/// Controls the placement of objects via a tap gesture.
/// </summary>
public class PawnManipulator : Manipulator
{
/// <summary>
/// The first-person camera being used to render the passthrough camera image (i.e. AR
/// background).
/// </summary>
public Camera FirstPersonCamera;
/// <summary>
/// A prefab to place when a raycast from a user touch hits a plane.
/// </summary>
public GameObject PawnPrefab;
/// <summary>
/// Manipulator prefab to attach placed objects to.
/// </summary>
public GameObject ManipulatorPrefab;
/// <summary>
/// Returns true if the manipulation can be started for the given gesture.
/// </summary>
/// <param name="gesture">The current gesture.</param>
/// <returns>True if the manipulation can be started.</returns>
protected override bool CanStartManipulationForGesture(TapGesture gesture)
{
if (gesture.TargetObject == null)
{
return true;
}
return false;
}
/// <summary>
/// Function called when the manipulation is ended.
/// </summary>
/// <param name="gesture">The current gesture.</param>
protected override void OnEndManipulation(TapGesture gesture)
{
if (gesture.WasCancelled)
{
return;
}
// If gesture is targeting an existing object we are done.
if (gesture.TargetObject != null)
{
return;
}
// Raycast against the location the player touched to search for planes.
TrackableHit hit;
TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon;
if (!EventSystem.current.IsPointerOverGameObject(gesture.FingerId))
{
if (Frame.Raycast(
gesture.StartPosition.x, gesture.StartPosition.y, raycastFilter, out hit))
{
// Use hit pose and camera pose to check if hittest is from the
// back of the plane, if it is, no need to create the anchor.
if ((hit.Trackable is DetectedPlane) &&
Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position,
hit.Pose.rotation * Vector3.up) < 0)
{
Debug.Log("Hit at back of the current DetectedPlane");
}
else
{
Debug.Log("PLANE DETECTED");
// Instantiate game object at the hit pose.
var gameObject = Instantiate(PawnPrefab, hit.Pose.position, hit.Pose.rotation);
// Instantiate manipulator.
var manipulator =
Instantiate(ManipulatorPrefab, hit.Pose.position, hit.Pose.rotation);
// Make game object a child of the manipulator.
gameObject.transform.parent = manipulator.transform;
// Create an anchor to allow ARCore to track the hitpoint as understanding of
// the physical world evolves.
var anchor = hit.Trackable.CreateAnchor(hit.Pose);
// Make manipulator a child of the anchor.
manipulator.transform.parent = anchor.transform;
// Select the placed object.
manipulator.GetComponent<Manipulator>().Select();
}
}
}
}
}
}