- Home /
Question by
kadykunde · Mar 13, 2018 at 05:58 PM ·
instantiatesavecustom editorsave scene
Objects instantiated in custom editor not saving.
I have the following custom editor:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(CheckpointSystem))]
[CanEditMultipleObjects]
public class CheckpointPositionSelect : Editor
{
private GameObject newCheckpoint;
void OnSceneGUI()
{
RaycastHit hit;
Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
if (Physics.Raycast(ray, out hit, 1000))
{
Handles.color = new Color(0.3f, 1f, 0.3f, 0.3f);
Handles.CylinderHandleCap(0, new Vector3(hit.point.x, hit.point.y + 2.5f, hit.point.z), Quaternion.LookRotation(Vector3.up), 5, EventType.Repaint);
SceneView.RepaintAll();
if (Event.current.Equals(Event.KeyboardEvent("C")))
{ //IMPORTANT PART
CheckpointSystem cps = (CheckpointSystem)target;
Vector3 placePosition = new Vector3(hit.point.x, hit.point.y + (cps.CheckpointPrefab.transform.localScale.z / 2), hit.point.z);
newCheckpoint = PrefabUtility.InstantiatePrefab(cps.CheckpointPrefab as Object) as GameObject;
newCheckpoint.transform.position = placePosition;
newCheckpoint.transform.parent = cps.transform;
newCheckpoint.name = "Checkpoint " + cps.transform.childCount;
Undo.RecordObject(newCheckpoint, "Checkpoint");
}
}
}
}
When I create an object (which is referenced in CheckpointSystem) the scene/editor doesn't "recognize" it, only when I move the created object's transform the changes are indentified.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612154524im_/https://answers.unity.com/themes/thub/images/avi.jpg)