Hi guys, i am currently modding a unity game and i need to attach scripts to weapons for the VFX to work correctly. I downloaded the mesh effects package that comes with scripts… i can easily attach the script in the editor without problems and its working. When i export the unity3d object the scripts get detached tho and ingame i am getting the warning “referenced script blabla is missing” and the effect doesnt look at all like in the editor. So what i did was take the script and compiled the code with a modding tool for that game to be added to the game. But as expected, its not that easy. As soon as i use that weapon the console throws the same error… so How exactly do i attach the script to the object correctly, do i have to add a reference to my script or what?
Unity builds a .dll of all the code in your game. Your modding code is not in the original game obviously, so I believe that’s why you’re seeing the errors.
I think the way modding is generally done is with a separate dll file that you add into the target game, and if the game is set up for modding, it knows to load that dll file, probably even call initialize and per-frame updates within it, optionally.
I’d check with people who are more familiar with modding, such as some modding sites. Here on the Unity forums we rarely would have a call for that knowledge since we just have our entire project, so modding is “just regular work.”
Yes I have the mods.dll and the modding tool injects the code at runtime. The problem is, when I create my unity3d file, the scripts I attached to my file in the editor are getting detached. So what I need to do is attach those scripts back to my prefab and instantiated objects at runtime. This is not something where modders could help me, maybe if someone is very experienced with unity.
So basically what I need is a script that attaches itself to the object at runtime like I can attach it to the object in the editor.
By definition, any asset stored on disk is always “detached” from any scripts/code.
It is Unity’s loading process that iterates the content of any given asset looking for identifiers that tell it what code to reconnect at runtime, and then Unity instances up the necessary code objects and gives them references to your assets.
Almost certainly it is this process that is failing. It could be due to any number of reasons, but one likely one is that you are building your assets with an incompatible version of Unity compared to what the target game was built with.
Again I suggest you approach the modding boards because they do this stuff all the time. We here “inside” of our Unity projects have no call for this knowledge, beyond what I have listed above.