Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Why can't my object be selected?

Discussion in 'EditorXR' started by wechat_os_Qy08D70r_Ee8Gx9_4iNwlJqZU, Jul 17, 2019.

  1. wechat_os_Qy08D70r_Ee8Gx9_4iNwlJqZU

    wechat_os_Qy08D70r_Ee8Gx9_4iNwlJqZU

    Joined:
    Mar 30, 2019
    Posts:
    4
    By inheriing from those interfaces, I just create a new tool.Here is the main idea :
    Interact with UI elements, then load a new model from disk.
    Finally, the model was successfully imported, but I found this new loaded model cannot be selected by controller. And the ray just pass through it!

    I tried to select this model(A) in the Hierarchy, then duplicate this model(B), and then B can normally be selected by my controller.
    How can I solve this problem?
     
    Last edited: Jul 17, 2019
  2. wechat_os_Qy08D70r_Ee8Gx9_4iNwlJqZU

    wechat_os_Qy08D70r_Ee8Gx9_4iNwlJqZU

    Joined:
    Mar 30, 2019
    Posts:
    4
  3. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,894
    Please, don't do this. Explain how you solved the problem.
     
  4. Taiyo_no_gosaiji

    Taiyo_no_gosaiji

    Joined:
    Dec 10, 2020
    Posts:
    4
    I've been through this.
    The solution is to use the IUsesSpatialHash interface.

    This is a simple code for testing.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor.Experimental.EditorVR;
    5. using UnityEditor;
    6.  
    7. public class cubeSet : MonoBehaviour, ITool, IUsesSpatialHash
    8. {
    9. #pragma warning disable 649
    10.     [SerializeField]
    11.     GameObject Cube;
    12. #pragma warning restore 649
    13.  
    14.  
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.         var cube = Instantiate(Cube, Cube.transform.position, Cube.transform.rotation) as GameObject;
    19.         Undo.RegisterCreatedObjectUndo(cube, "Create Cube");
    20.         this.AddToSpatialHash(cube);
    21.     }
     
  5. amirebrahimi_unity

    amirebrahimi_unity

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    369
    Thanks for explaining how you solved this. Yes, this is required because we decided with EditorXR that we didn't want to just add collision meshes to all your objects so that scene picking could occur. While it may be useful for editing it may not be desired in your actual build.
     
    Taiyo_no_gosaiji likes this.
unityunity