Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    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:
    4,322
    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:
    400
    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.
  6. tran10

    tran10

    Joined:
    Nov 30, 2020
    Posts:
    13
    Hello @Taiyo_no_gosaiji, Thank you so much for your demo
    In EditorXR 0.4.12, I think we don't have UnityEditor.Experimental.EditorVR as well as IUsesSpatialHash, so how can we select the imported object in play mode?
    We need to add another things?

    Thank you so much.
    Tran10