I don’t have a lot of experience with nested prefabs. I understand how they work but haven’t tried designing a lot of them.
What are the things to look out for when deciding how to up nested prefabs/prefab variants? I kinda expect the “favor composition instead of inheritance” principle to come into play but it doesn’t seem completely the same as when you’re just dealing with code.
Some basic things make sense to me:
- If your game had a dangling crane that holds an item (like a fruit, for points), you’d make a prefab for the crane, and a prefab for the fruit.
- If your game had a regular goblin, and a strong goblin, it makes sense for the strong goblin to be a variant of the regular one, maybe with different values in its serialized fields. If they had extra moves, it wouldn’t be huge a problem. You could think of the regular goblin as the strong goblin, but with some moves disabled.
But I worry about the setups that say “a player and an enemy inherit from this thing” 'cause the player could very well have all sorts of abilities and movement rules that don’t apply to enemies and vice versa, even if they have similarities. Surely, some enemies could fly or pass through walls or go underground or even split into several GameObjects/Transforms.
It could be fine especially if you know what they’re going to be and consequently, what they’re never going to be. But if you’re at the start of development for a game that’s not solidified, wouldn’t deciding this inheritance too early make adjustments unnecessarily difficult?
As someone who tends to set up their important GameObjects into nested hierarchies anyway, I think it makes sense to using the “nesting” aspect for composition. eg, I’d put my collider and the “damage receiving” script on a child Transform instead of on the root Transform. If I make this attackable GameObject child a prefab, I can add that to any prefab that needs to be attackable regardless of what it is.
Does this way of proceeding have serious problems or is it what’s generally recommended?