Weather Event Hook

how to use the Weather Event Hook , since I don’t have enough experience in unity and I don’t know how to use it, and I would like to use it to do alarms in elver for example

The Weather Event Hook is a mod hook that functions as an event listener for weather events. Mod hooks are components that you can add to game objects from within Unity.

This mod hook includes triggers for the following events:

  • Day
  • Night
  • Full Moon
  • Rain
  • Snow

As a component, you can configure an attached mod hook from the Inspector tab – just like you would for any other Unity component. It may be helpful to read Unity’s documentation to better understand their scripting API, and what you can do with it.


Example: I want to add a Weather Event Hook to my custom barricade, so that when it’s raining it uses a different model.

There’s multiple ways to do this. One way is to have the prefab include two game objects, with their own models. I can then activate (and deactivate) the game objects depending on whether or not it’s currently raining. Unity’s GameObject.SetActive allows for this.

In my prefab, I’ve added two game objects. I’ve named these Model_0 and Model_1.

Barricade prefab

You may notice that Model_0’s icon is a bright white, while Model_1’s is a more subdued gray. This is because I’ve set the Model_0 game object as active, and the Model_1 game object as inactive.

Model_0 game object
Model_1 game object

Model_0 has a Weather Event Hook attached. When it is raining, I want Model_0 (itself) to deactivate, and for it activate Model_1.

Model_0 component

Model_1 also has this mod hook attached. When it’s done raining, the opposite should happen. I have it activate Model_0, and deactivate Model_1 (itself).

Model_1 component

Note that there’s other ways I could achieve what I’m trying to do in this example.

E.g., I could have just disabled the mesh renderer instead of the entire game object. Doing it that way instead would have been more efficient, as only one game object would’ve needed the mod hook attached. (For something like Audio, you’d have an Audio Source attached to a game object, and then you could enable/disable that depending on the weather.)

But this will work for what my example is trying to do, so we can just go ahead and bundle the mod.

If we test it in-game, we get this:

1 Like

I’ll try the object one and read some unity guides, and is it the same with sounds?

You could just deactivate/activate a game object that includes an audio source, yeah. Just note that a deactivated game component does nothing – so you’d need at least two game objects so that you can both start doing stuff and stop doing stuff depending on the weather.

As an example, here’s hold I have my game object set up:

This “Fire” gameobject includes a an AudioSource component. This gameobject is deactivated to start with. When it rains, I have a different gameobject activate this one when it’s raining, and then deactivate it when the rain stops.

This audio track I have set to loop, but you might not want yours to loop. In which case, you’d just configure your AudioSource to whatever makes sense for your purposes.


From my previous post, I did suggest that you could do this way as well:

to rectify, since I am quite dumb, I must have 2 identical models, one must have an audio source and the other does not , in my case a military radio, using the video you sent me as an example, which one will play an IATA code and the other which is inactive, right ?

No. This is just something that my example used, as my example was to create something that changed models depending on the weather state.

It’s a little confusing, but my intention was for that to be a general explanation of how the weather event hook works, and how gameobjects work (notably: if you deactivate yourself, then you can’t continue to run scripts from yourself – you need to use an active gameobject to run scripts).

There’s multiple ways to do what you’re specifically trying to do, but to keep it simple you can do this:

  • Your prefab has two gameobjects.
  • One is your model (for example, named Model_0). This object is activated.
  • The other has your audiosource (for example, named Audio). This object is deactivated.
  • You can only run scripts from an activated gameobject. So all of your scripts will be on your Model_0, as this is already activated, and is never going to be deactivated for the purposes of what you’re doing.
    • Model_0 has a Weather Event Hook component added to it.
    • On Rain Begin (), a script targets your Audio gameobject and activates it.
    • On Rain End (), a script targets your Audio gameobject and deactivates it.

Hi, I’m back, I was creating a 3d model for the radio, so I did what you explained, but I can’t test it because I have a problem with exporting it as a master bundle. the error is the next:


image

what i have:
image
image
image
image

Re-import tags/layers. Double-check everything is tagged correctly, and that your masterbundle is set up correctly (in Unity, in the masterbundle’s .DAT file, and that you have a 1:1 file hierarchy for your Bundles).

I made a new project in unity to have it with more order and it works xd
image
I put a saturated audio and now I’m deaf but happy
thanks for being patient with me

1 Like

It seems that the mistake was mine, since now that I mark it as children it works

Last question, the ids between “Spawns”, “Items” , “Vehicle” and the objects one can collide between them?

IDs for each asset type do not collide with each other. However, GUIDs can easily collide with each other, so please make sure each asset you make has a unique GUID.

2 Likes

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