Renaming pre-existing script in src/scripts causes Unity confusion

I made a script named Rotate.ts in src/scripts with a Rotate class, and then later on I tried renaming that file to Pulse.ts. Then when I went back to Unity, it got confused and can no longer attach the generated C# scripts to game objects with the attached error.

I’ve tried making an entirely new script Test.ts with a class Test and I get the same error now. Does anyone know how to escape this error so I can attach C# scripts to game objects again?

Original Post on Discord

by user 690021744479830061

I did confirm that there are no compile errors and the file name and class match. This error only started appearing once I tried to rename the same file and class within that file. It seems to be unable to realize that the problem is now solved or that there’s been a replacement?

by user 690021744479830061

I also updated the file references in register_types.js. But still getting the Unity error

by user 690021744479830061

EEeeeep nevermind :see_no_evil: I guess restarting Unity fixed it!

by user 690021744479830061

There are indeed a couple cases that our Component Compiler doesn’t perfectly catch right now, renaming in some cases being one of them - glad you got it resolved!

To recap, your order was:

  • create .ts script → c# component was generated
  • rename .ts script → new c# component was generated and old not deleted (correct ?)
  • restart Unity, press play → things work?

^ That is almost correct, just missing the step where I also had to update the naming in register_types.js as well

by user 690021744479830061

To clarify what is happening:
C# scripts are not deleted when scripts in src/scripts are being added/renamed/deleted. The reason is that you can manage multiple web projects in a single Unity project and the c# script might be used somewhere else still.

Scripts are being deleted and cleaned up when you use NpmDef files because they know which scripts belong to which package and thus will delete the c# script when you delete or rename the typescript-class