Hi there,
I’ve recently gotten into creating custom inspectors for some simple editor tools, I’ve run into a few issues but mostly overcome them.
I’ve now run into a strange issue and I’m not sure if I’m going crazy or if it’s something I just don’t understand about how editor scripts work.
In the code below this is basically what I’m doing:
-
Wait for click in scene
-
On click, create new GameObject
-
Add a component to that object
-
That component has a public variable (furnRef.FurnitureName) of an AssetReference from the Addressables pipeline
-
Set that AssetReference to match the one currently set in my master object (Furnplacer.assetRef)
-
Then set position, scale, etc.
This mostly works as expected BUT the issue is that when I change the AssetReference in my master object any objects created by it are also updated when they should stay as they were when created.
If I make a change to the script, and the editor recompiles, any objects created beforehand will no longer be affected by the master changing.
I’ve been trying to figure out what it is, I’ve tried a lot of different potential fixes, debugging, and read a lot of stuff online but I can’t for the life of me figure out what is causing this.
Is there some basic part of editor code that I’m missing that explains this behaviour? is it a bug?
If anyone can help, make any suggestions, or even test the code in your version of unity if you’re a saint I’d be very grateful, anything helps!
Cheers,
Joe.
private static bool m_editMode = false;
public static FurniturePlacer FurnPlacer;
void OnSceneGUI()
{
FurnPlacer = (FurniturePlacer)target;
if (m_editMode)
{
Selection.activeGameObject = FurnPlacer.gameObject;
if (Event.current.type == EventType.MouseDown)
{
//Spawning object with asset reference
AssetReference assetRef = FurnPlacer.FurnToPlace;
GameObject NewObj = new GameObject();
FurnitureReference furnRef = NewObj.AddComponent<FurnitureReference>();//Getting my component which I'll add the AssetReference to
furnRef.FurnitureName = assetRef;//Setting the asset reference
//Set position, location etc.
//...
//...
}
}
}