x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Non-Pawn Actor with AI controller & Movement Component

Hello everybody,

I have a question, maybe a noob question but I need to know before I go too in depth with my game. I'm making an RTS game in which the base class of every units and buildings is Actor.

insane paint skills

After doing the building part and checking that everything is working fine with the inheritance, i've decided to do the unit part. But I came across a very deep conception problem, which is : unless I am wrong, I do need an AI controller to use moving functions from WheeledVehicleComponent (for tanks and trucks) and CharacterMovementComponent for infantries. BUT, as I'm using Actor as a base class, I can't get a controller from that.

And even tho I could, I cannot inherit from both "PlayerUnit" and "WheeledVehicle". I'm really in a dead-end here, if you guys have a solution, I would love to hear it !

the SelectableActor is a class where I put the health, max health, health bar (widgetComponent), the owner of the actor (which commander owns it) and create the mesh component of the actor (without loading anything, of course). SelectableActor split into PlayerActor and CivilianActor (which is not represented on the drawing). PlayerUnit contains stuff like the speed of the unit.

The only way I see is by duplicating a lot of code for multiple "blood lines". For instance, doing a Building line with their own health, MaxHealth, etc, and do the exact same thing for another lane, let's say the infantries. So that Buildings could be simple actors while infantry could start from Characters. That's insanely dirty but I cannot think of another way :/

Product Version: UE 4.14
Tags:
more ▼

asked Jan 17 '17 at 03:31 PM in C++ Programming

avatar image

Gnougnou
141 17 16 28

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I guess there is not much to do but to refactor all my stuff.

The workaround is to use an interface that can be used as a cast identifier : Before, I was casting to SelectableActor to check and add the actors to the selected actors array (typical RTS box selection). Now, I cast my Actor as the interface. So any class that implements that interface will be concidered clickable (health bar showing up for instance).

Instead of using one main class, I use a Pawn line for my buildings (because turrets will need an AI controller and BT), Characters for my Infantries and probably WheeledVehicle for my tanks. Those 3 main lines of inheritance will implement the interface so they all can be concidered as clickable by the selection box.

I did the Building line already, and it seems to work really fine.

more ▼

answered Jan 18 '17 at 04:58 AM

avatar image

Gnougnou
141 17 16 28

avatar image Forcas Apr 03 '19 at 01:40 PM

Oh man ! casting an actor to the Interface type actually works ! i almost had redone the whole thing again because of this ! u r great !

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question