Hiding Other Components In Editor

Hello All. I have a MonoBehaviour that requires a Rigidbody and A ConstantForce.

However, What I’d like to do is to hide these 2 components from the editor, as they should never be accessible to the user.

I realize that I have to create a custom editor, but this will only allow me to influence my classes.

Does anyone have any idea on how to get around this?

    [RequireComponent (typeof(Rigidbody))]
    [RequireComponent (typeof(ConstantForce))]
    
    public abstract class BasicBehaviour : MonoBehaviour
    {
    	void Start()
    	{
    		gameObject.rigidbody.freezeRotation = true;
    	}
    	void Update()
    	{
    		if (Input.GetMouseButtonDown(0))
    		{
    			//add force
    			constantForce.force = (-transform.forward);
    		}
    		if (Input.GetMouseButtonUp(0))
    		{
    			constantForce.force = Vector3.zero;
    		}
    	}
    }

So again, what I would like to see in the editor, is just my script with its fields (I have a custom editor) and not the Rigidbody/ConstantForce.

Ok. So with the help of @PAEvenson’s advice, I came up with a solution.

The key here is to have a custom editor. in that editor’s OnEnable() you can get the other components that you don’t want, and apply the hide flags.

This is your run time class.

using UnityEngine;
using System.Collections;
[RequireComponent (typeof(BoxCollider))]
public class TestHide : MonoBehaviour {

	// Use this for initialization
	void Start () 
    {
        
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

This is your editor class.

using UnityEngine;
using UnityEditor;
[CustomEditor (typeof(TestHide))]
public class TestHideEditor : Editor {

	void OnEnable()
    {
        var castedTarget = (target as TestHide);
        castedTarget.GetComponent<BoxCollider>().hideFlags = HideFlags.HideInInspector;
    }
}

void Reset(){//called as soon as component is added in inspector
this.hideFlags = HideFlags.HideInInspector;
}

Object has a member called hideFlags. You should be able to use it like so:

void Start()
    	{
    		
                this.hideFlags = HideFlags.HideInInspector;
    	}