Pretty much title; I’m trying to figure out a workflow for things like particle effects, sounds effects, etc. Am I expected to really add every single item, effect, sound, enemy, character, etc as a prefab in the Network Manager? Is this the intended way of doing one-off things, or have I misunderstood? Any workflow ideas would be very helpful.
It depends on where you parent these.If the parent is networked, the child prefab needs to be networked too.
Assuming something like a bullet impact effect, that should not be parented to any network object.
If the effect is attached to a weapon the player carries, it should be attached to the weapon to begin with (nested prefab), meaning there is no need to instantiate the fx but rather just enable or start/stop the effect. The effecct is of course not synchronized over the network but rather each client plays that effect locally when it receives the notification of that client shooting.
Is that the only other valid workflow with NGO? I just don’t see how that scales.
For example, in my game currently, there are item pickups that randomly spawn on the ground. Right now I have two, so that’s two more Network Prefabs. Even if I parent them under an “Item Pickup Parent”, I still have the actual instantiated game objects for the item on use to work to worry about. So that’s like either 5 different network prefabs for two items, unless I figure something out, and I just can’t see a way to “smartly parent” all this in a way that I just need to enable/disable items.
Maybe it’s just me as a bad developer or something, but I really can’t stand how dirty all this feels. I’ll look through my project and try and find a way to “condense” game objects, though.
Still, if anyone else could give me information on your workflows that would be great.
Assuming pickup is just some item that floats above the ground, animates and has some effect to make it stand out, then I would probably implement it as follows:
A prefab “PickupItem” that contains the collider, MeshFilter, MeshRenderer, ParticleSystem, Audio component and whatever else pickup items need. It also has a PickupItem script attached - on network spawn you would simply pass the ItemType (an enum) to that script and you’d have a static helper class that returns a PickupItemDefinition instance (it may choose to cache those rather than load them every them) for a given ItemType.
PickupItemDefinition has these fields:
- Mesh
- ParticleEffect
- Audio
- … any other assets the pickup item may need to use
So there’s one prefab for all items, the rest is just data you need to set up for each item to be unique both visually and audibly.
Not every tiny bit needs to be a separate GameObject.
Yeah, that would work well for the item pickups for sure, or I could find a way to make that workflow work for them, since they’re just different meshes, an outline, particle effect, etc- They’re all more or less the same there.
But when you use the item, the effects are going to be totally different. For example, one item in the game is an object that pulses and heals for a limited time, while another is the giant rock wall which is comprised of many rock walls that jut out on use. So they have completely different behaviors, their own scripts, etc.
I’m just spitballing here, but maybe I could do something similar to the pickups, where, since all the used items are GameObjects with a script, I could have a Network Prefab that is sorta like an IOU for the item, with a reference to which item is used- and then on use, the Network Prefab will spawn whatever the item is? So one Network Prefab for all the items
How does that sound to you?
EDIT: Nope doesn’t work because in order to spawn them in I’d have to have them as a network prefab- I’m losing my mind here lol.
Honestly, the biggest issue I’m having are things like spell VFX. Some of them have particular things about them, such as needing to be attached to the player, which I’m having a hard time condensing into a single NetworkPrefab that would work for all or even most effects. I guess that’s the challenge of game development though.
Btw love the help you’re giving here. Highly highly appreciated.
The main takeaway from network programming is to split up logic and visualization. To the game it should not matter what kind of effect you apply to an item, a spell, a weapon. Calculation of hits and damage is done on the server-side by perhaps checking actors in range and so on. Ideally there should be no client-side script that does these calculations and damage distribution, and then sending that over to the server. This would also make it easier to cheat because this is effectively client-authoritative damage dealing.
Probably the easiest way for networked attachments is to have them all set up in the player prefab, and you’d just enable/disable the game objects. Not sure if SetActive is still disallowed in NGO but you can always disable the MeshRenderer (or vfx) components, or SetActive is disallowed only on the root of the prefab where the NetworkObject component resides but child objects can be set inactive. You may want to try that.
Another tip, not sure if this helps here but certainly good to know: consider bypassing the usual parenting if that is troublesome with NGO reparenting. Parent-child hierarchical relationships are just a convenience thing really, having an object follow another by making it a child and it works as expected. But you can always have another object follow another via scripts and a reference to the other object, then update the follower’s transform as needed to make it stick to the target object (or even a bone of the target).
Yeah, SetActive works on NGO, that was my earliest testing actually. But thanks for all he helpful advice. I guess a lot of this is getting creative with how you set up your game. I’m currently butchering the old item system to accommodate for online, so again, thanks for all the help!