Unity -> Xenko, confused about script inheritance and other

Hi all,

I have started developping a Tower Defense game in Unity a month ago. I have been amazed with the flexibility and features Xenko offers at such an early stage and have decided to port my existing code to use Xenko. I have some questions:

  1. All towers in my game inherit from a base class Tower that is a Monobehaviour (equivalent of Component in Xenko). I then derive Canon, Turret etc… Then when I do raycasting to select a tower for example, all I do is a raycastedObject.GetComponent<Tower>(), if that returns a reference, it means it is a concrete Tower or a derived class (Canon, Turret …). Does the Get<>() work the same way in Xenko?

  2. My game is tile based, and builds a level from a file in a grid format. I instantiate the tiles from prefab and put them in their right position. In Unity I had a problem with too many draw calls (400 with just the level tiles which is a lot for a mobile game). Is there a way to have “prefab instances” that get drawn together ?

Those are all my questions for now. Thank you for your help!!

1 Like

Hi,

I believe than answer to your first question is “yes”. I have not tested it myself though. Looking at the engine source and the documentation. An entity stores it’s components in a EntityComponentCollection. According to the documentation EntityComponentCollection.Get<>() “Gets the first component of the specified type or derived type” and returns “The first component or null if it was not found”.

No idea about your second question though.

Oh, how did I miss that! That’s perfect for my needs. Thank you :slight_smile:

You’re welcome.

I also just thought about your second question. If you plan on using SpriteComponents for your tiles. The SpriteComponent renderer does use a Sprite3DBatch to render them. So there could possibly be some batching, depending on what options you use and if they share textures etc.

Actually I am using 3d boxes as tiles in my games so definitely not using Sprites. In Unity I share the material accross my instantiated prefabs and use StaticBatchingUtility class to batch them together (although sometimes it does not seem to work and still incurs >1 draw call per tile which is a lot). Maybe it will come in handy if I ever use sprites in the future.

If your tiles are static (not changing at runtime), you can already create a Scene with many models, and compile it as a single Model using the “Prefab Model” asset (release notes: https://doc.xenko.com/1.8/ReleaseNotes.html#prefab-model)

However, it doesn’t help for dynamic cases (tiles changing as you play), where actual GPU instancing is needed. We’ll work on it at some point though!

2 Likes