Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Gavor · Oct 29, 2016 at 03:51 PM · c#javascriptproject

Converting js project to c# - replacing script references

I have just finished converting all my .js files to .cs and fixing the errors. The code compiles!

Now for the super tricky part, how do I replace all the script references on all my objects? If I remove the .js files I obviously get the "missing behaviour" error in the Inspector. I'm happy manually replacing the files by dragging and dropping the .cs file onto the reference in the Inspector then removing the .js file, but Unity won't let me do that. I could have sworn I had done that in the past.

Ideas? I'm a bit frazzled after a full day of conversion and a bit frustrated to get to the end and find that the script replacement is waaay more difficult than I had thought it would be.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Zitoox · Nov 05, 2016 at 08:45 PM 0
Share

I didn't get what you are doing. You are just importing your scripts and then changing from "Example.Cs" to "Example.Js" ?

avatar image Gavor · Nov 06, 2016 at 07:11 AM 0
Share

So I had a large project of all .js files. I converted all the javascript to C# by making a copy of the .js files, rena$$anonymous$$g them .cs and doing the code conversion. So I had two sets of files, one with .js extension and one with .cs extension. Problem is, you can't just delete the .js files and expect Unity to update all your component references. In the end I found a way to get it working, via some subterfuge. Answer below.

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Gavor · Nov 06, 2016 at 09:14 AM

To have Unity simply pick up the cs files and use them as the script component references in place of the old js, I had to fool it into thinking the old js file references were the cs files. After some research into how it makes a database of files and handles references, I discovered it's all in the meta files! So, the fix was:

  1. Rename all .js.meta files to .js1.meta

  2. Rename all .cs.meta files to .js.meta

  3. Rename all .js1.meta files to .cs.meta

So now each .cs file has the file reference (which resides in the .meta file) from the previous .js file of the same name. When you open Unity it sees the references just uses the cs file instead of the js in all components. From a cursory look in the .meta files (and a week of testing), it seems to work 100%.

I used a bulk file renamer to rename all the files, Bulk Rename Utility.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Romano · Oct 27, 2017 at 07:25 PM 0
Share

This helped me a lot a year later, thanks!

avatar image HenningKO · Jul 20, 2018 at 07:32 AM 0
Share

This worked for me! Great. Thanks Gavor. Small note: To avoid breaking public references on your scripts TO OTHER SCRIPTS, you have to do all this js.meta to cs.meta conversion at once, without opening Unity in between... but I didn't find it too hard to go one script at a time and drag the script refs back in on the inspector when they became available...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

What scripting language should I use for a multiplayer project? 1 Answer

Multiple Cars not working 1 Answer

A simple ladder in C# or Js 3 Answers

How to make 3D text appear after conversation is complete? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges