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"

What is the best way to create a health system?

Hi, I want to make a basic health system in my project. In this system I want to be able to damage barrels (Actors), robots (Pawn) and Humans (Characters). Now I would like to have just one damage function and one health variable I have to access.


First I tried just to make a parent child system. But the problem is, that if I inherit from AActor, I can't use any Pawn and character classes. If I inherit from APawn or ACharacter, I can't use the base AActor class anymore.


I could rewrite the AActor class, but I don't think that is a good idea, because all other classes use these codes. Plus my engine breaks when I try that.


Next I tried to make the functions in the controller. But first, actors don't have any AiControllers and second you would have to rewrite the function in the player controller.


My last idea were interfaces, but in the interfaces I can't set any timers (like the time delation from dispawning after the Actor dies. Plus I can't access GerWorld(), because that's an AActor function and not Interface. So I can't cast to the MainPlayerController.


With this I don't know any other easy ways to create a health system. Thx for the help!

Product Version: UE 4.20
Tags:
more ▼

asked Sep 03 '18 at 05:25 PM in C++ Programming

avatar image

Aneos
25 3 3 9

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

This is usually done using interfaces.

Interface methods must be overridden (implemented) in all objects that inherit the interface so you can access all needed functions while implementing the interface in the objects.

more ▼

answered Sep 03 '18 at 06:24 PM

avatar image

dZh0
1.2k 6 5 8

avatar image Aneos Sep 03 '18 at 06:41 PM

Thx for the answer. As I said in my question, I can't access "GetWorld()" in my I-Interface part of the class. So do I have to override every function in the implemented class to set timers or is there an other way?

avatar image dZh0 Sep 03 '18 at 10:01 PM

Yes. The project will not compile if the interface functions are not overridden in the class implementing the interface. This means that when you implement it in the AActor you will have access to GerWorld().

Keep in mind that you can implement a function with empty body in any calss.

avatar image Aneos Sep 04 '18 at 05:10 PM

Thanks for the answer. I think I will be alright now.

avatar image dZh0 Sep 03 '18 at 10:17 PM

You can check the wiki and the official documentation if you are unsure on how to implement interfaces.

(comments are locked)
10|2000 characters needed characters left
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