0
\$\begingroup\$
 public class TileObject : MonoBehaviour {

////some code was here
public PlayerAnimator playerAnimator;

////some code was here


public void SetTileObject(int xPos, int yPos, TileData tileData)
{
   ////some code was here

    if (tileData.player)
        playerAnimator = new PlayerAnimator();
}

And my question do i lose any performances(or memory) doing this instead of inheritance or something else.(tileObject can be other than player)

\$\endgroup\$
  • 2
    \$\begingroup\$ Don't assume something is causing you performance issues until you see actual problems, then use a profiler to see what's wrong. \$\endgroup\$ – Almo Jul 12 '18 at 14:26
2
\$\begingroup\$

There doesn't seem to be anything resource-intensive in your question. You are falling victim of Premature Optimisation. From a design point of view, your idea is similar to organising objects with component (rather than inheritance). Each of them has its own ups and downs, and sometimes different uses.

Which of them is faster? Does it really matter? They've both been used by professional game engines, so they both can create promising results.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.