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 Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    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,318
    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