Hey guys, sorry for my noob question, but I have made a script with a Public Transform variable.
I then dropped a gameobject into that slot so i can use the gameobjects transforms in the script.
The problem is I need the gameobjects xyz transforms to be displayed in the inspector.
I also frankly dont know how to “access” the xyz coordinates from the gameobject.
You could make another vector3 variable and associate it with the object at run time. If you just need to see the transform properties of the object in question just look on the object itself.
Well transform.position is already a vector3 but if you want to display that information in the editor I’m pretty sure you are going to need a custom editor script. I’ll throw something together in a few hours if nobody solves it before then. Cheers!
The native behaviour of the Unity inspector does not show you all of the transform properties of a transform variable. That information is displayed by the built-in inspector script for the Transform component. What you are asking for is a way to show real time transform properties in the inspector, not the Transform component that is attached to the GameObject that contains your script, but the Transform components attached to other GameObjects that you have dragged into variable fields on that script. If you ABSOLUTELY need to see the Transform properties for these other GameObjects in the inspector all at once, I can’t think of any reason why you would need to do this, this is the best solution I can give you:
Attach this script to the object you want to display all this transform data
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class TransformList : MonoBehaviour {
public List<Transform> transformList;
public void AddTransform() {
if(transformList == null)
transformList = new List<Transform>();
transformList.Add(null);
}
public Transform AtIndex(int i) {
if(transformList != null){
if(i < transformList.Count && i > -1){
return transformList[i];
} else {
Debug.LogWarning("Index out of range. Returning null transform");
return null;
}
} else {
return null;
}
}
public Transform ByName(string name) {
if(transformList != null){
if(transformList.Count > 0){
for(int i = 0; i < transformList.Count; i++){
if(transformList[i].name == name)
return transformList[i];
}
}
}
return null;
}
}
Then make a folder called “Editor” in your project and put this script in there
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
[CustomEditor(typeof(TransformList))]
public class TransformListEditor : Editor {
private TransformList _target;
public override void OnInspectorGUI(){
VerifyRequirements();
DrawList ();
}
public void VerifyRequirements() {
if(_target == null)
_target = (TransformList)target;
if(_target.transformList == null)
_target.transformList = new List<Transform>();
}
public void DrawList() {
if(_target.transformList != null){
if(_target.transformList.Count != 0){
for(int i = 0; i < _target.transformList.Count; i++){
EditorGUILayout.BeginVertical("button");
_target.transformList[i] = (Transform)EditorGUILayout.ObjectField(_target.transformList[i], typeof(Transform), true);
if(_target.transformList[i] != null){
_target.transformList[i].position = EditorGUILayout.Vector3Field("Position", _target.transformList[i].position);
_target.transformList[i].eulerAngles = EditorGUILayout.Vector3Field("Rotation", _target.transformList[i].eulerAngles);
_target.transformList[i].localScale = EditorGUILayout.Vector3Field("Scale", _target.transformList[i].localScale);
}
EditorGUILayout.EndVertical();
}
}
if(GUILayout.Button("Add Transform")){
_target.AddTransform();
}
}
EditorUtility.SetDirty(_target);
}
}
I went ahead and made two methods for returning these transforms. You can return them with a reference to the TransformList class that contains them by calling one of the following methods:
As I’m sure you can see, what you are asking for is not as simple as you thought it was going to be.
If someone can come up with and easier way to do this, I would love to hear about it! I do a lot of work with custom inspector scripts and anything I can do to save myself time will be welcomed with open arms.
Believe me man, I suggested all of this. Read up further. What I did is like crushing daisies with an anvil because he’s under the impression he needs to see all that data in the same place.
I can’t think of any reason why he would need this. Sure, it has a place, but it certainly isn’t anything that he would be using it for; unless he’s making some sort of editor extension.
Im trying to make a grid.
What I did was place cubes and each cube will be a point on the grid.
So i now assigned all the cubes to a script to get all of their coordinates
For debug purposes I want all the cubes(grid coordinates) to show in the inspector so i can easily compare it with the position of the selector to select a gridpoint.
Probably not the ideal solution my friend, but if that is what you want to do, that custom inspector I wrote for you will show all the transform information. What are you using this grid for? Depending on how many cubes you have it could get QUITE expensive.
Nah brah, you are crushing daisies for some reason. dont “my friend me” and try to convince me to do over complicated shit. I dont fall for it.You are trying to give a noob coder a hard time by trying to redirect his attention to more complicate stuff. All I wanted was to have a vector (xyz) display in the inspector, and I managed without doing fukn custom whatever you suggested.
There’s no need to get hostile. I gave you an elegant solution that would display transform data in real time in the editor as well as in play mode. Isn’t that what you asked for? Given that I went out of my way to code a complex system like this for you, do you think your comment was really justified? I’m sorry if I offended you as that was never my intention, but do you think someone who was trying to help you deserves an outburst like that? I was not trying to steer you in the wrong direction at all.