Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
3
Question by ramkesh · Jun 06, 2020 at 08:10 AM · scripting problemprefabspriteassetbundleasset

Can we make a script an Addressable in Unity ?

I am able to create Prefab using Addressable . If i am creating new prefab and upload addressable on server . It generated in already made game build . But when i attach script on prefab . Script does not generated in game . It only generate with prefab with script if we make build of game .Same if we edit script of prefab . Please let me know can we make script addressable?

Comment
Add comment · Show 1
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 Anshul_Goyal · Sep 20, 2021 at 08:06 AM 0
Share

Hello @ramkesh have you find any solutions on including scripts with addressable?

2 Replies

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

Answer by Bunny83 · Jun 06, 2020 at 10:36 AM

No, you can't ^^. All code has to be compiled into assemblies and depending on your build platform might even be completely AOT compiled into native code. The Unity engine runtime does not even ship with the C# compiler.


Depending on the platform and scripting backend there are ways to load compiled assemblies dynamically at runtime. However that has to be done manually through reflection. However this is of course not possible on any AOT platform (WebGL / iOS / IL2CPP / ...).

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
2

Answer by DanVioletSagmiller · Oct 08, 2021 at 09:51 PM

I was able to include scripts in bundles that would download separatly and import live, which ran just I had to do something to trigger the code to start, and used a Locator service, so the script could embed itself and replace the current pieces it wanted (and use existing ones)


As far as I was aware, Addressables is a glorified topper to bundles. I have not tested this in Addressables itself, but the premise worked in Unity 2017.


[UPDATE] This is invalid. After some discussion I went back and tested further. The script was included in the bundle, BUT, it was also in the initial build, and so when requested to be loaded by a scene element, it was already part of the assembly. Any attempts push new code after the initial build failed. A long time ago I tried to create a test case specifically for this, but I wrote a bad test with a false positive. :(

Comment
Add comment · Show 6 · 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 Bunny83 · Oct 08, 2021 at 10:10 PM 0
Share

Have you actually read my answer? A Unity build usually does not ship with a C# compiler and C# scripts don't magically compile themselfs into assemblies. This is done in the editor. You can not load individual script files. As I said, there are ways to dynamically load pre-compiled assemblies through reflection. However that's not possible on any ahead-of-time compiled platform. Are you sure, what the scripts you try to load from bundles aren't part of the Unity project when you build it? Unity generally includes all script files in your project when your project is compiled. So you may had the impression that you somehow load it dynamically when in reality the script was already part of the build.

avatar image DanVioletSagmiller Bunny83 · Feb 04 at 08:58 AM 0
Share

(I am wrong, see next reply from me) Yes, I read your post. But I have actually done this. My statement wasn't based on conjecture. Why would you assume a script included in an asset bundle wouldn't get compiled? Do you think that unity produces only one assembly to run the game from? I have done this with IL2CPP before, an if I recall right a WebGL. I couldn't use reflection to load it, reflection couldn't even pull a list of assemblies that were loaded at the start, but when the object being loaded included a reference to the script held inside, that was loaded with it, it triggered it anyway, allowing the new script to take over. I cannot claim to know why it works, but it does. I used this as a functional plugin system to allow live plugins to an app. I literally used this to replace scripts inside a locator service.

However, I keep seeing posts that defaulting to saying you can't with various reasons. And I haven't seen anyone else doing it. So, I'll plan on creating a video proof for it. Given your consideration that maybe the script was in the original assembly as a possibility of why my script worked, I cannot validate, as I don't have the code in front of me. However, I'll post back here with a humble belief, or a proof. :)

avatar image andrew-lukasik DanVioletSagmiller · Feb 04 at 09:56 AM 0
Share

Dan, we're all rooting for you to be right but there are valid doubts that need to be dispelled. For example, what Bunny83 said is exactly what Unity manual once stated explicitly:

Including scripts in AssetBundles

AssetBundles can contain scripts as TextAssets but as such they will not be actual executable code. If you want to include code in your AssetBundles that can be executed in your application it needs to be pre-compiled into an assembly and loaded using the Mono Reflection class (...)

https://docs.unity3d.com/550/Documentation/Manual/scriptsinassetbundles.html

Show more comments
Show more comments

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

290 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

Modern Asset Handling - Multiple Projects? 0 Answers

What does this mean exactly? "A script behaviour (script unknown or not yet loaded) has a different serialization layout when loading" 0 Answers

Storing a part of a complex asset in an asset bundle 1 Answer

Resize a 3D prefab without affecting scale 2 Answers

How to set a prefab SpriteRenderer.sprite using script in editor? 1 Answer


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