Catching Code: How to Hook Fish in Fortnite Creative
Catching Code: How to Hook Fish in Fortnite Creative
Welcome to the dock! Today, we are going to build a mini-game where players can catch fish. But this isn't just clicking a button. We will use Verse code to make a "Fishing Zone." This zone will give players a fishing rod. When they use it, they catch a prize. You will learn how to give items to players using code. This is a core skill for making any game. Let's dive in!
What You'll Learn
- What a Fishing Zone is.
- How to use Verse to give items to players.
- How to listen for a Player Event.
- How to link code to a game device.
How It Works
Imagine you are at a real fishing hole. You need three things. First, you need water. In Fortnite, this is the Fishing Zone. It is a special area on the map. Second, you need a rod. This is an Item. Third, you need someone to fish. This is the Player.
We will write a small script. This script watches the Fishing Zone. It waits for a player to step inside. When a player enters, the script says "Hello!" and gives them a rod. This is called an Event. An event is something that happens in the game. The player entering the zone is the event. Our code reacts to that event.
Think of it like a doorbell. The doorbell is the code. The person pressing it is the player. When the person presses the button, the bell rings. That is all our code will do. It will ring the "give item" bell when the player arrives.
Let's Build It
Here is the code for our Fishing Zone. Copy this into a Verse file in your project.
# This is our Fishing Zone device
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# We name our device "FishingZoneDevice"
FishingZoneDevice := class(creative_device):
# We add an item_spawner_device to give items to the player
# Place and link an Item Spawner device in your island,
# then bind it to this property in the Details panel
@editable
ItemSpawner : item_spawner_device = item_spawner_device{}
# We add a mutator_zone_device so we can detect players entering
# Place and link a Mutator Zone device in your island,
# then bind it to this property in the Details panel
@editable
FishingZone : mutator_zone_device = mutator_zone_device{}
# This runs when the game starts
OnBegin<override>()<suspends> : void =
# We tell the zone to watch for players
# "AgentEntersEvent" fires when a player steps inside
FishingZone.AgentEntersEvent.Subscribe(OnPlayerEnterZone)
# This function runs when a player enters
OnPlayerEnterZone(Agent : agent) : void =
# We spawn the fishing rod through the Item Spawner device
# The Item Spawner is configured in the editor to hold the rod
# note: Verse has no direct runtime item-creation API; item_spawner_device is the standard approach
ItemSpawner.SpawnItem()
# We print a message to the screen
# This helps us see the code working
Print("You caught a rod!")```
Let's look at the important parts. The first part is `OnBegin`. This is like setting up your fishing gear before you start. It tells the device to start watching. The second part is `OnPlayerEnterZone`. This is the hook. When a player steps into the zone, this code runs. It tells the Item Spawner to spawn the rod directly into that player's inventory. Finally, it prints a message. You will see "You caught a rod!" in the debug window.
## Try It Yourself
Now it is your turn to fish!
1. Place a **Fishing Zone** device on your island.
2. Add the Verse code above to it.
3. Play your island and walk into the zone.
4. Check your inventory. Do you have a rod?
**Challenge:** Can you change the code to give a different item? Try changing `"CreativeFishingRod"` to `"ShieldFish"`. See what happens when you walk in.
## Recap
You just made a device that gives items to players. You used an event to watch for players. You used code to create and give an item. This is how many games work. You watch for actions. Then you react. Great job!
## References
* https://dev.epicgames.com/documentation/en-us/fortnite/using-fishing-items-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-fishing-consumables-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-items-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite/using-items-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite/using-fish-items-in-fortnite-creative
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add using-fishing-items-in-fortnite-creative to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.
References
Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.