Skip to main content
16 events
when toggle format what by license comment
Oct 11, 2024 at 1:44 comment added Fen1kz @Zibelas my question is all about how generally should "tower shooting component" communicate with some arbitrary "TargetingSystem". I'm lost how to build extensible, testable and modular architecture where my shooting component would "just request" TargetingSystem.
Oct 9, 2024 at 21:41 answer added Kevin timeline score: 1
Oct 9, 2024 at 20:31 comment added Kevin @Zibelas ScriptableObjects can be used for global systems that do not require the functionality of a MonoBehaviour or don't need to be in a scene. For example, I often build my spawn pools as ScriptableObjects, so a spawn pool can be referenced from different scenes and prefabs.
Oct 9, 2024 at 7:40 comment added Zibelas For example the TargetingSystem I would solve like this: Your enemies get either an interface or component ITargetable. In your targetingSystem script and with a simple collider you can just check on the collision enter if the other one has the ITargetable and if yes, add it to some interal list of TargetingSystem. In your tower shooting component you request or get the enemy matching directly from TargetingSystem (like closest, most hp, etc). Enemies do not need to communicate with the tower, there is no linking done. If they are in range of tower (collider), they get targeted.
Oct 9, 2024 at 0:30 history edited Fen1kz CC BY-SA 4.0
approach #5 - service locator
Oct 8, 2024 at 20:17 comment added Fen1kz @DMGregory I need general knowledge and guidance rather than advice how to do specific scene. I'm afraid example scene would give me answers like "hey just make a pair of singletons and call it a day". What I want is to make my basics good so I will extend this in all directions. I've added an example
Oct 8, 2024 at 20:16 history edited Fen1kz CC BY-SA 4.0
added example
Oct 8, 2024 at 20:07 history edited Fen1kz CC BY-SA 4.0
added example
Oct 8, 2024 at 18:43 comment added DMGregory I think I'm getting a sense of your general problem space. To help make answers more concrete and applicable to your needs, could you edit your question to walk us through a sample scene? What systems does it need, what needs to be spawned dynamically vs. can be pre-configured in the scene, what spawns what, and what needs a reference to what? With this kind of detail, answers can propose a specific implementation that serves those needs.
Oct 8, 2024 at 16:38 comment added Zibelas It is mainly a thing for setting up the game/ level. Some things will always be in the level and should not make you much of a problem. I'm currently using a mix of your 1 & 3. The events can be great but take some time to get used to. And usually systems/ managers are singletons. You do not need two managers for the same thing in your scene
Oct 8, 2024 at 16:34 comment added Fen1kz I don't think RequireComponent is a case in my example. I need GridSystem on a different component, therefore I cannot use RequireComponent.
Oct 8, 2024 at 14:47 comment added Zibelas You can always use docs.unity3d.com/ScriptReference/RequireComponent.html to make sure that on your object is the needed one. ScriptableObject are better used as holders for stats like how much total life your enemy has, speed, etc. If you change the values, they stay changed
Oct 8, 2024 at 12:21 comment added Fen1kz I cannot link my prefabs in prefab folder with Systems in scene in editor. If I do it in code via gridSystem = GetComponentInParent<GridSystem>(), I have to pray there's a parent with GridSystem component or I get error in real time If I do via "FindObjectsOfType" to search for any GridSystem, this is also bad because if I happen to have 2 GridSystems, I wouldn't control to which one my component is connected to.
Oct 8, 2024 at 12:01 comment added DMGregory "Cons: I cannot set these systems in prefabs" why not? We might be able to help you solve that con. Can you also show an example where making sure the system is non-null is difficult when dynamically instantiating a component? We may be able to ease that too.
Oct 8, 2024 at 11:58 history edited Fen1kz CC BY-SA 4.0
added 18 characters in body
Oct 8, 2024 at 11:48 history asked Fen1kz CC BY-SA 4.0