Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 796531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:39:16+00:00 2026-05-14T22:39:16+00:00

Yes, this is another question about my game engine, which is coming along very

  • 0

Yes, this is another question about my game engine, which is coming along very nicely, with much thanks to you guys.

So, if you watched the video (or didn’t), the objects in the game are composed of various components for things like position, sprites, movement, collision, sounds, health, etc. I have several message types defined for “tell” type communication between entities and components, but this only goes so far. There are plenty of times when I just need to ask for something, for example an entity’s position.

There are dozens of lines in my code that look like this:

SomeComponent comp = (SomeComponent)entity.GetComponent(typeof(SomeComponent));
if (comp != null) comp.GetSomething();

I know this is very ugly, and I know that casting smells of improper OO design. But as complex as things are, there doesn’t seem to be a better way. I could of course “hard-code” my component types and just have

SomeComponent comp = entity.GetSomeComponent();

but that seems like a cop-out, and a bad one.

I literally JUST REALIZED, while writing this, after having my code this way for months with no solution, that a generic will help me.

SomeComponent comp = entity.GetComponent<SomeComponent>();

Amazing how that works. Anyway, this is still only a semantic improvement. My questions remain.

  1. Is this actually that bad?
  2. What’s a better alternative?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:39:17+00:00Added an answer on May 14, 2026 at 10:39 pm

    Without knowing the overall design of your game, it’s difficult to know if that pattern, in isolation, is good or bad. If it works and performs well, the only potential argument against it is architectural- will it scale?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yes, I know, yet another question about mutable objects. See this for general background
I have already posted another question about this, but no one seemed to know
yes this is an iOS programming question. I need to calculate the exact time
This question falls into the yes - this works, yes - this is ugly,
I know the Sales pitch answer is yes to this question, but is it
Yes, this is a programming-related question, if a little indirectly. For better or worse,
Yes another question that is a little Unique because I cant find the same
My own answer to this question is YES, but I'd like to hear from
Yes, I realize this question was asked and answered, but I have specific questions
another question about formats and informats: formats are using for output (for show me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.