How do I use ModHook?

I would like to create an item using ModHook.
But I am not sure how to use it on Unity.
Is there a page that outlines how to use it?
I have looked around, but I can’t find a site that explains it in detail and I am having a hard time understanding it.
If you know of any, please let me know.

*I do not speak English, so I am using DeepL to translate.
I am sorry if the text is difficult to understand or if there are any rude expressions.

1 Like

Have you already looked at our official documentation for mod hooks? It explains the functionality of each one:

You can add a mod hook to a Unity gameobject just like you would for any other component. (They’re included in the .unitypackage at the ...\Steam\steamapps\common\Unturned\Bundles\Sources filepath, so if you haven’t added those unitypackages to your Unity project yet, you need to do so first.)

1 Like

Thanks for the reply!

Yes, I have seen your page before.
Thanks to that page, I have a general understanding of what each ModHook does.
(I even got as far as placing a ModHook on an object in Unity.)

But because I am a programming novice, I could not understand how to use that ModHook in Unity.

For example
“On Enable()” and “On Disabled()” in the “Activation Event Hook”.
I would like to know how to use them.

I was wondering if there is a detailed tutorial like this?

Unfortunately, none of the mod hooks have a detailed walkthrough or video tutorial. The documentation assumes that the modder is (generally-speaking) already familiar with using Unity to create mods for Unturned.

Some additional details about each mod hook can be found if you open up the script’s file in a text/code editor. Although some important information may get lost in translation.

There are some topics/posts on this forum that do go into more detail about mod hooks. For example, I’ve made a couple posts about the Weather Event Hook and the Activation Event Hook. You can find them in this topic: Weather Event Hook - #3 by MoltonMontro

The Activation Event Hook is an event listener. When the gameobject is activated, or deactivated, this mod hook is triggered. Here are the summaries for its two functions:

// Invoked when component is enabled and when the game object is activated.
// Invoked when component is disabled and when the game object is deactivated.
// Note that if the component or game object spawn deactivated this will not be immediately invoked.

The Activation Event Hook cannot activate/deactivate the gameobject on its own. You should use it with something else that can activate/deactivate the gameobject, such as another mod hook.

All mod hooks are script components. Here are the generalized steps you’d use to configure any mod hook that is an event listener:

  1. Add the mod hook to the gameobject or the component. You should add it to the thing that you want to be listening for the event to occur.
    What is listening for the event?

  2. Choose which gameobject or component the mod hook should effect. By default, this is assigned to “None (Object)”. You should assign this to whatever you want to change, modify, or otherwise affect after the event occurs.
    What should be affected?

  3. Select what should happen when the mod hook is triggered. This could be a function available from Unity, or it could be another mod hook.
    What should happen?

1 Like

Thank you so much for all the details!
It was very easy to understand with the pictures.
I’m going to try out some things right away!
I will try to learn more about Unity! :blush:

I have learned from MoltonMontro on Twitter before.
I am always saved by MoltonMontro’s kindness.
Thank you very much.

I’m having a hard time finding materials for modding Unturned, so I open Unity and stare at it every day.
Then I found this forum the other day.
I’m going to look at every single ModHook topic you taught me about, as well as other posts!

Thank you very much! :grin:

1 Like

I’m glad that the information I provided was helpful to you. Good luck with your modding projects!

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.