Search Unity

Using Multiple (but same functioning) Scripts in 1 object

Discussion in 'Scripting' started by AzaiKang, May 27, 2020.

  1. AzaiKang

    AzaiKang

    Joined:
    Mar 17, 2019
    Posts:
    3
    I have a Player object, and it contains 3 scripts that executes an Object pooling function.
    1 is the WeaponPrefab - The prefab of the object pooling weapon,
    2nd is the WeaponSummon - That summons or instantiate the WeaponPrefab via loop function,
    and 3rd is the WeaponMain that allows where the WeaponPrefab can move freely by setting X, Y and Z values.

    This script is for the melee weapon only; which makes it a total of 3. But when I use the same script for more variety of attacks like Heavy Attacks, Projectile, AOE and Shield, that makes it a total of 15 scripts in 1 object. Is this good for my Player performance?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,914
    Why is your prefab a component on your GameObject?
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    The only person who can answer this is you, running your game on your target hardware. As for individual component performance, open the Profiler window, attach it and find out. Nobody here can do it for you.

    I recommend you follow some basic tutorials and lay your first game out in a "traditional" way, such having a separate object pool object, game manager, etc.

    It's pretty much a prerequisite that you at least try and fully understand the "traditional" way of doing things before you start trying experimental new ways of doing things, at least if you want to have some measure of success.
     
    AzaiKang and Joe-Censored like this.
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Less code running usually equals better performance, but generally with game development you need to take a pragmatic approach. Instead of asking if something is good or not, consider asking only if it is good enough for what you are trying to accomplish. That usually involves judgments on acceptable levels of performance of what you already have, how long would it take to develop an alternative and possibly better way of doing something, what the potential gains are from doing so, and in the end is all that extra work really worth it?

    To answer that you need to do testing yourself, which usually involves the Profiler when it comes to Unity, and if you're talking about potentially a lot of work you might want to create a prototype of your alternative approach and test that as well to reduce reliance on guesstimation.

    As already mentioned though, typically an object pool isn't implemented on a GameObject representing a character in the game. It would be implemented on its own GameObject. There's several reasons for this, but the most obvious is at some point in the game you probably will want to destroy the character, like if the character dies.... Oops just destroyed the object pool system too.
     
    AzaiKang likes this.
  5. AzaiKang

    AzaiKang

    Joined:
    Mar 17, 2019
    Posts:
    3
    The prefabs are the hit sensors that hits through enemy AI's. I have created the prefab so it can be upgradable with my Upgrade System. The prefabs represents as light attack, heavy attack, projectiles, etc.
     
  6. AzaiKang

    AzaiKang

    Joined:
    Mar 17, 2019
    Posts:
    3

    I did some testing using the Profiler, it works fine for Android and PC. But when I start doing some test to the build, it always crashes in Android devices lower than Android 6 and it has a (not really, maybe like 30 seconds) loading time. I did some graphical changes, reduces everything, removed the shadows, but the draw calls of the scene is reaching in the value around 20-150 Draw calls. I believe this is because of the prefab from my scripts.