• 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 /
This question was closed May 27, 2014 at 10:56 PM by vexe for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Blue Astronaut · May 03, 2014 at 09:19 PM · programmingmodify

Any way to modify Unity's code?

Hello!

So - I've been thinking about this for a while, but I haven't found any topics on it. The Unreal engine allows users to adjust the engines internal code to help them make games. I get this from a topic on the unreal website about BioShock Infinite, where the article says: "(Irrational Games) have replaced or heavily modified vast portions of Unreal Engine 3 for BioShock"

Is there a way to do the same thing with Unity? Modify the engines code to add something/fix something etc? If so - would this be legal?

Any help is appreciated!

Comment
Add comment · Show 5
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 Owen-Reynolds · May 04, 2014 at 07:13 AM 1
Share

$$anonymous$$ight be an apples and oranges situation. Some engines are kind of rigid, and you have to modify them to do almost anything unique. Unity, not so much.

avatar image Jeff-Kesselman · May 04, 2014 at 06:12 PM 0
Share

Very much so,

On a benchmark where I wrote the Sieves of Eratosthenes in Unreal Script and Unity/C#, the unity version was 300 times (30,000%) faster.

There ar some occasional annoyances where you can't get at things yould like to in Unity, but thats true with most engines and generally there are work arounds that function fine.

avatar image Kavorka · May 04, 2014 at 09:49 PM 0
Share

$$anonymous$$ay I ask, the 300 times faster, are you talking about the time it took you to write the code? If so, were you equally acquainted with both engines?

avatar image Eric5h5 · May 04, 2014 at 10:28 PM 2
Share

Clearly he's talking about execution speed.

avatar image Jeff-Kesselman · May 05, 2014 at 02:37 AM 1
Share

Corrct I was talking about execution speed of the two benchmarks.

It took me about 20 $$anonymous$$ to code and run in Untiy because I was familiar with it.

It took me about an hour to translate to Unreal script and run it because I was not familiar with that environment.

However I have been coding for better then 30 years so moving between environments and C-syntax OOP languages is not a big deal.

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Jeff-Kesselman · May 03, 2014 at 09:39 PM

Yes, you buy a source license.

Its costs "upwards of 6 figures" last time I checked.

Unlike UDK however, Unity has a perfectly speedy scripting language in C#/Mono so you can do most anything you need to from the scripting level.

Comment
Add comment · 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
5

Answer by vexe · May 05, 2014 at 03:25 AM

Allow me to be brave (or maybe stupid lol), and say yes! But not in a legitimate/straight-forward manner, and just for the managed side of Unity (its managed assemblies)

Recently I found out about the 'beautiful' dynamic keyword, I was so happy, you have no idea! Only soon to discover Unity's rusty Mono version doesn't support it! It broke my heart! I decided it's time for payback, Unity broke my heart, it's time to break 'it'!

So I read about all assembly/dll modifications/hacks/edits, etc. I came to find out about Mono Cecil - it's really powerful! - You can modify .NET assemblies with it with ease! For example.

Then I discovered Reflexil!

So I hooked it up to my reflector (.NET Reflector or JustDecompile - It's a plugin there you can install it for free - Unfortunately it's not available for ILSpy)

Now, there's something really stupid in Unity, if you make a PropertyDrawer for a list/array, it will forcefully display the array size field even if your drawer's OnGUI is freckin empty! That is PLAIN stupid! - I didn't like that. So I thought I'd find this stupid method and do something about it.

Sure enough, after a very simple reflect, I found it sitting at UnityEditor.EditorGUI.ArraySizeField - But we are not interested in it actually, we're more interested into the caller, who's using/calling this? If you're using ILSpy, you could right click on the method and collapse "Used by", you'll see that it's called by UnityEditor.EditorGUI.SinglePropertyField (Which is the method called when you do a PropertyField) - it has a giant switch statement for the propertyType that's how it figures out what control to draw for your property.

This is the relevant section for us:

 case SerializedPropertyType.ArraySize:
 {
     EditorGUI.BeginChangeCheck();
     int intValue2 = EditorGUI.ArraySizeField(position, label, property.intValue, EditorStyles.numberField);
     if (EditorGUI.EndChangeCheck())
     {
         property.intValue = intValue2;
     }
     break;
 }

Now, what can we do about it? I tried a couple of things with Reflexil:

  1. I tried deleting the whole switch statement lol. Unity didn't like that, it didn't even execute with the patched dll.

  2. I tried nopping the opcodes for the ArraySizeField call, Unity ran, but gave some invalid IL code exceptions.

  3. The successful shot, was not to modify anything, but was just to redirect the call to ArraySizeField to a method of my own! (This won't change the actual code, but just the call opcode - So as far as Unity's considered, everything's legit!)

alt text

But this didn't really solve the property drawer problem, it seemed that if you make a property drawer for an array/list, the drawer will be applied to the individual elements not the whole array. AND, now you can't even see the size of public arrays/lists (in other words, the array size field is now gone, not just for customly drawn arrays/lists) - But... the point of this is that this method of redirecting calls, WORKED!

A couple of notes:

  1. If you get errors from unity, (unable to load type, type-safety stuff, etc) - Try and verify your patched assembly using peverify.exe

  2. Of course, the patched dll has to go to your Unity's directory. In Windows, it's: "C:\Program Files (x86)\Unity\Editor\Data\Managed"

  3. PLEASE don't do this if you don't know what you're doing! There are high chances of you unintentionally breaking things.

  4. Make sure you backup all the DLLs you mess with.

  5. OMG is this illegal??! Who F* cares? let's light some flares :)

  6. Of course, if you try to publish an asset using a patched DLL, the asset store might not accept it. So you'd have to find a way around it, maybe a simple way would be to do this whole thing by code (via Mono Cecil), make a dll for your legit helper classes, include the injection code there and obfuscate the dll or something Idk use your imagination.

I encourage this only as an experiment for educational purposes only - Just careful not to shoot yourself in the foot.


owned.png (113.2 kB)
Comment
Add comment · Show 4 · 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 fafase · May 09, 2014 at 07:27 AM 0
Share
   "O$$anonymous$$G is this illegal??! Who F* cares? let's light some flares :)"

Unity cares, it is in the agreement when you start using Unity (and somewhere in the EULA) that you will not try to modify the software.

$$anonymous$$aybe this one:

  1. Ownership

The Software is licensed, not sold. Unity and/or its licensors retain ownership of the Software including all intellectual property rights therein. The Software is protected by copyright law and international treaties. Unity reserves all rights in the Software not expressly granted to you in this Agreement. You will not delete or in any manner alter any Unity or third-party copyright, trademark or other proprietary rights notices or markings appearing on or in the Software (including the runtime portion thereof).

avatar image vexe · May 09, 2014 at 07:59 AM 0
Share

Well if they don't want users to modify their code cause they're pissed about some of their outright stupid things they do in their code, like this stupid array size field, or not giving us any feedback from when an assembly reload happens, or even selectively disabling the settings context menu, etc etc (I could go on for days) then they shouldn't be surprised! they should provide us with the flexibility we need, and fill in the gaps so that users don't feel the urge to do things their own way.

avatar image fafase · May 09, 2014 at 08:46 AM 0
Share

Well, I do agree, I would also like to know what happens internally to make it all better on my side and I do agree that the support is too often relying on the community but the problem is legal.

You agree in the first place not to access and modify the internal functioning, so if you are not happy with what they do you should not use it. This is what their lawyer would tell you at the court while handing over the fine the judge has signed.

Or as mentioned in the other answer, you buy the right to modify the code, that is what most studios do but it costs a kidney.

avatar image TechSupportIncoming1 · May 09, 2014 at 09:31 PM 0
Share

Whoa! This is super! Thanks for sharing this useful tweak with us :D

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

26 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Whats wrong with this PerlinNoise function 0 Answers

is there a diffrence between unity C# and normal C# 1 Answer

Anybody help me how to convert unity file in unity web player 1 Answer

Cloud recognition in Vuforia 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