• Mods are now organized as resources. Use the Mods link above to browse for or submit a mod, tool, or prefab.

    The TFP Official Modding Forum Policy establishes the rules and guidelines for mod creators and mod users.

Help Registering Hits for Unity Prefabs

usHallgrim

Refugee
Hi All,

TL;DR I can't figure out how to make a unity prefab "hittable" for 7DTD.

So I have created a tomato_sprout tomato_growing and tomato_harvest (harvestable for the player). I put a box collider around each plant. I double-checked in prefab mode and in the hierarchy panel that this was applied to the parent fbx/mesh. Appled a tag "T_Mesh_B" to all of the fbx/meshes (I saw somewhere that might be needed). Renamed and dragged them all from the hierarchy panel into a prefabs folder. Set them all to Asset Bundle zl_foodandcrops. Ran Build AssetBundles. Copied zl_foodandcrops over to {MyMod}/Resources.

The result: I am able to plant the tomatoes and watch them go to growing, then to harvest. The plant orientations are correct, I'm color vision impaired so I'm sure the colors are off but the textures/material looks to have mapped properly.

BUT I CANNOT HIT THE DARN THINGS!

I tried 2 different ways to get them to work.

(1) Just inherit everything but the model from seedPotato1 (vanilla). Of course this reverts back into a potato as it grows, and then I can hit the potato but not while it is in the sprout stage with my tomatosprout mesh.

(2) I also tried to define everything the best I could figure out. I can't hit the tomato plant at any stage of growth (none of the 3 meshes register hits as far as I can tell).

Here is my block definitions (but I don't think they are the problem I think it's something I'm doing wrong in Unity 2202.3.62f1).

Any help would be greatly appreciated I've been at this no hit problem for hours and hours.

<!-- Tomato Seed-->

<block name="testTomatoSprout">
<property name="Extends" value="plantedPotato1"/>
<property name="Model" value="#@modfolder:Resources/zl_foodandcrops?Assets/Crops/Tomato/Prefabs/tomatosprout.prefab"/>
<property name="CustomIcon" value="seedTomato"/>
<property name="CreativeMode" value="Player"/>
</block>


<block name="plantedTomato1">
<property name="Extends" value="cropsGrowingMaster"/>
<property name="CustomIcon" value="seedTomato"/>
<property name="CreativeMode" value="None"/>
<property name="PlantGrowing.Next" value="plantedTomato2"/>
<property name="UnlockedBy" value="craftingSeeds"/>
<property name="Shape" value="ModelEntity"/>
<property name="Model" value="#@modfolder:Resources/zl_foodandcrops?Assets/Crops/Tomato/Prefabs/tomatosprout.prefab"/>
<property name="ModelOffset" value="0,0,0"/>
<property name="Collide" value="movement,melee,bullet,arrow,rocket"/>
<property name="PassThroughDamage" value="false"/>
<property name="IsTerrainDecoration" value="false"/>
<property name="Material" value="Mplants"/>
<property name="MaxDamage" value="10"/>
<property name="MultiBlockDim" value="1,1,1"/>

<!-- <property name="Model" value="#@modfolder:Resources/flagGUNSok.unity3d?flagGUNS" /> -->
<property name="PlaceAsRandomRotation" value="true"/>
<drop event="Destroy" name="plantedTomato1" count="1"/>
<property name="SortOrder1" value="B982"/>
<property name="SortOrder2" value="0000"/>
<property name="Tags" value="seedSkill"/>
<property name="SoundPickup" value="seeds_generic2_grab"/>
<property name="SoundPlace" value="seeds_generic2_place"/>
</block>
 
Try putting the collider on the top parent, so tomatosprout. And try T_Block as the tag. Also, if you haven't search here for Xyth's Unity tutorial project if you don't already have it and grab the TagManager.asset from it and copy it to your Unity project's ProjectSettings folder and overwrite the one there.
 
Try putting the collider on the top parent, so tomatosprout. And try T_Block as the tag. Also, if you haven't search here for Xyth's Unity tutorial project if you don't already have it and grab the TagManager.asset from it and copy it to your Unity project's ProjectSettings folder and overwrite the one there.

FIXED due to getting pointed it the right direction! So I got Xyth's v1TagManager.zip from his github https://github.com/7D2D/Templates-and-Utilities and also watched a couple of his videos on YT and noticed he Created an empty rootGameObject, renamed it to something Prefab (I renamed mine to follow his convention to TomatoSproutPrefab). But then you add your fbx object as a child. I figured out to add a texture and material to the child fbx if you need to (as I did). BUT the tag and collider should be set to the rootGameObject. I rebuilt my assets, updated the XML to the new prefab name and it worked.

Thank you, thank you, thank you ddubyah, xyth and all the others that have put in the legwork to make this stuff work!
 
I put together a bulleted workflow that I think works well once you get a bit familiar with the Unity interface. This is my first time in Unity so take this list with a grain of salt.
Markdown (GitHub flavored):
Unity Workflow Worksheet for 7 Days to Die Modding

Prerequisites:
1. You need to properly install an AssetBuilder script.
2. You need to properly install 7DTD specific TagManager.Asset.
3. Both are presently available via https://github.com/7D2D/Templates-and-Utilities

Step 1: Import Your Assets
- Start a new Unity scene (matching the game’s Unity version, e.g., 2022.3).
- In the Project Window Create new folder(s) for your .fbx models and it's subcomponents (e.g. textures, submeshes).
- Import .fbx model (and subcomponents) via Assets > Import New Asset into it's own folder.
- NOTE: You can build your materials from your texture later.
- Do NOT drag anything into Hierarchy yet.

Step 2: Create the Root Object
- In Hierarchy: Right-click > Create Empty.
- Name descriptively, e.g., TomatoSproutPrefab.
- Reset Transform: Position (0,0,0), Rotation (0,0,0), Scale (1,1,1).
- Root is always empty GameObject for prefab parenting.
    - You will add a collider and tags later.

Step 3: Add Child Objects (Hierarchy Setup)
- Drag imported .fbx into Hierarchy under the root.
- If multiple sub-meshes appear, keep them nested.
- Adjust pivot at the base (ground level for plants).
- Keep hierarchy simple: Root > Mesh > Sub-meshes.

Step 4: Apply Texture/Material
- Root stays clean (no Mesh Renderer/Material).
- Assign materials to child mesh (.fbx):
  - Import texture (if not already imported).
  - Create new material or reuse imported one.
      - (e.g. TomatoSproutMaterial)
  - Drag texture to Albedo slot of material.
  - Apply material to child Mesh Renderer.
- Verify UV mapping and visuals in Scene view.

Step 5: Add Components (Collider, Tag, etc.)
- Select Root GameObject.
- Add Collider (Capsule Collider preferred for plants).
  - Example: Center (0,0.5,0), Radius 0.15, Height 0.8.
- Set Tag: e.g., T_Mesh_B (for plants) or T_Block (for blocks).
    - Other tags may apply for specialized blocks.
- Keep scripts minimal; plants typically don’t need them.

Step 6: Finalize and Save Prefab
- Root must be the prefab, not the mesh alone.
- Drag Root from Hierarchy to Project window to save as .prefab.
- Add prefab to AssetBundle (e.g. zl_foodandcrops)
- Test in Scene view: Gizmos show collider coverage.

Step 7: Export Asset Bundle
- Use community export scripts (e.g., from Xyth or SDX toolkits).
    -- i.e Assets > BuildAsset Bundles > Windows64
    -- Windows 64 also works for Linux as of this writing for prefabs.
- Copy to mod’s Resources folder as {AssetBundleName}.unity3d.

Tips & Consensus Notes
- Root handles colliders/tags, child handles visuals (mesh/material).
- Avoid Mesh Colliders unless shape requires it; Capsule preferred.
- Use power-of-two textures (512x512, 1024x1024, etc.) for compatibility.
- Naming: simple, consistent, no spaces or special characters.

Hitbox check for (plants/mesh blocks)
- Root object is the prefab and has the only collider.
- Tag is on the root (e.g., T_Mesh_B for plants, T_Block for block-likes).
- Child FBX holds Mesh Filter + Mesh Renderer and materials (root stays visual-empty).
- Capsule Collider on root roughly covers the stalk/base (not the wispy leaves).
- Layer = Default; collider not set as Trigger; no scripts needed.
- Keep Scale = (1,1,1) on root; adjust child mesh if offset is required.
- Add prefab to the correct AssetBundle; export bundle; place .unity3d in {YourRootModFolder}/Resources/.
- You will should have <property name="MultiBlockDim" value="1,2,1"/> in your XML for plant that is between 1 and 2 meters tall.
 
Back
Top