Profile image

Need Help with Custom Gun Mods (Using Unity)

9,821 Adiarka454  7.2 years ago

Hello, I may not have any rep around here, but I sincerely need help. I have seen various custom guns in the 'Mods' page, especially the ones made by Gestour (Vickers Gun, .50 cal Browning, etc.). These lovely weapons can fire bullets/shells of different damage levels, muzzle velocity, shapes and sizes. They also play a custom firing sound not originally found in the game.

My question is, how do you create such weapons? I have made some weapon mods using Unity and XML myself (albeit low quality, which is why they're not uploaded), but they are mostly just stat, color, and value modifications of currently existing in-game objects (I made an Antimatter Bomb out of the Beacon Light). I tried opening the weapons above and tried to see what's going on through XML, to no avail.

My main problem is that I cannot seem to fully understand how scripts work in SP, as you cannot simply create a custom C# script and expect it to work in-game (I learned the hard way...). I tried tweaking said scripts to make them similar to the ones shown in the tutorial by Jundroo themselves, but it ended up in a hailstorm of errors. Dear Modding Lords, please guide me!

  • Log in to leave a comment
  • Profile image
    4,431 MIWTheGamer

    @HellFireKoder you once were like us, you even said to ask the devs, lol, gut gemacht, and Gute Nacht.

    5.8 years ago
  • Profile image
    9,821 Adiarka454

    @HellFireKoder I understand. I'll look further into this myself, and thank you so much for all your help!

    7.1 years ago
  • Profile image

    @Adiarka454 man, that's a bummer... I thought the devs made modding work on Mac, but idk, you'll have to ask them for more information I guess. Sorry.

    7.1 years ago
  • Profile image
    9,821 Adiarka454

    @HellFireKoder I have rebuilt the mod using Unity 5.3.6, sadly the result is more of the same. Exact same errors appeared. Is making the mod on a Mac the cause of this or something?

    7.1 years ago
  • Profile image
    9,821 Adiarka454

    @HellFireKoder Alright thank you, this might take a while as I'm nowhere near my home. I'll message again once I get it up and running.

    7.1 years ago
  • Profile image

    @Adiarka454 yeah, make sure you get 5.3.6, not newer stuff (they have a download archive).

    7.1 years ago
  • Profile image
    9,821 Adiarka454

    @HellFireKoder I'm currently using 5.3.1f1
    I should probably update right?

    7.1 years ago
  • Profile image

    @Adiarka454 I'm not sure what's going on, so... I'm going to ask... you're using Unity 5.3.6, right?

    7.1 years ago
  • Profile image
    9,821 Adiarka454

    @HellFireKoder I tried pasting the codes into new modifier scripts, unfortunately the problem still persists. I believe it has something to do with the following errors in the Unity console:
    .
    .
    InvalidOperationException: Operation is not valid due to the current state of the object
    System.Collections.Stack.Peek () (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections/Stack.cs:321)
    UnityEngine.GUILayoutUtility.EndLayoutGroup ()
    UnityEngine.GUILayout.EndHorizontal ()
    UnityEditor.EditorGUILayout.EndHorizontal () (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorGUI.cs:6754)
    Jundroo.SimplePlanes.ModTools.Editor.PartEditor.ShowInitializedGUI (Jundroo.SimplePlanes.ModTools.Parts.Part part)
    Jundroo.SimplePlanes.ModTools.Editor.PartEditor.OnInspectorGUI ()
    UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1231)
    UnityEditor.DockArea:OnGUI()
    .
    .
    InvalidOperationException: Operation is not valid due to the current state of the object
    System.Collections.Stack.Pop () (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections/Stack.cs:329)
    UnityEngine.GUILayoutUtility.EndLayoutGroup ()
    UnityEngine.GUILayout.EndVertical ()
    UnityEditor.EditorGUILayout.EndVertical () (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorGUI.cs:6820)
    UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1244)
    UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1028)
    UnityEditor.InspectorWindow.OnGUI () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:352)
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    .
    .
    They appear everytime I create a new set of the 3 part modifier scripts. How should I approach this?

    7.1 years ago
  • Profile image

    @Adiarka454 hmm... That's what happens when I change the project assembly name, and forget to resave all objects with scripts on them... If you haven't resaved since building the mod, try that, or if you have... Maybe the mod tools get confused when you take part modifiers from another project, so you could try using the mod tools to create a new part modifier, and then paste the relevant code from the original so that it's basically a new copy?

    7.1 years ago
  • Profile image
    9,821 Adiarka454

    @HellFireKoder I've reworked everything from the ground up, and the weapon is question is in its own seperate mod now. However, I get the following error in the Dev Console:
    .
    .
    Modifier 'PrototypeMod_LaserCannon' defined in mod 'Prototype Mod' could not be loaded because the modifier type 'LaserCannon, PrototypeMod-Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' could not be found.
    .
    .
    I didn't use a GetComponent to call in the laser's script, but rather attached it to a separate game object and wrote in the Part Behaviour script to load said object and parent it into the Wing Gun clone when not in the designer.

    7.1 years ago
  • Profile image

    @Adiarka454 you can run a normal script for sure if you add it at runtime... In other words, have a part modifier which just does AddComponent to add the normal script, though this does mean you can't set the script up in the inspector.

    7.2 years ago
  • Profile image
    9,821 Adiarka454

    @HellFireKoder I have made a script in Unity in a separate project which enables an object to use a Line Renderer to fire a laser beam. It worked great, being able to fire at different ranges, having an animated texture, emit sparks, etc. In it, an IEnumerator is used to manage the laser beam itself.

    I tried to put the script in a custom part modifier script attached to a clone of the Wing Gun. I then noticed that it wasn't going to work because it didn't have the "using System.Collections" line at the top, so I added it. When the mod was run ingame, the part itself didn't even show in the list and actually caused errors in the Dev Console and "blocked" other custom parts to load from the same mod. This was proven when I removed the laser gun, everything else in said mod worked perfectly.

    So can I actually run a normal C# script in SP without it being a Part Modifier Script, or maybe adding "using System.Collections" was a mistake?

    7.2 years ago
  • Profile image

    What are the errors, and exactly when do they happen? What's the script?

    C# scripts work fine in SP, though there may be quirks for scripts on parts specifically.

    Also, nothing goes on in XML except storage of data...

    If you would like to learn C#, this looks nice, and for anything Unity specific you can Google.
    Also, perhaps you can try exactly (as possible) following the tutorials, and then tweaking small things to test the waters?

    7.2 years ago