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"

Editing Variables in Decorator

I realize that Decorators are not supposed to have their values changed, hence they are defined as const. But say that I have a reference to a custom-defined Actor, and I want to use Cast to get some specific variables from that Actor; without having to Cast<> inside the CalculateRawConditionValue() function every time I need to get that variable. Is there a way to initialize that Cast once and never do it again?

Product Version: UE 4.9
Tags:
more ▼

asked Oct 10 '15 at 09:41 PM in C++ Programming

avatar image

daniyalmirza
8 4 4 7

avatar image staticvoidlol Oct 12 '15 at 07:01 AM

Not that I know of. At the risk of giving some unsolicited advice, usually when I run into cases like this I re-evaluate my class design. I.e. if you need to do casts to access subclass elements it means that your OOP design is not optimal. I.e. you are introducing subclass-specific conditions and handling into the design, which is not good.

One solution to this is to have functions/properties on your base class which can then be accessed by anything with a reference to that base class (even if the specific reference might be of a subclass).

E.g. suppose you have a class hierarchy as follows:

Weapon

----MeleeWeapon

--------KnifeWeapon

--------BaseballBatWeapon

----HandgunWeapon

--------M1911Weapon

--------GlockWeapon

and you have the following (admittedly contrived) functions on the following:

 MeleeWeapon:
     // Returns how long it takes to slash
     float GetSlashTime()
     
 HandgunWeapon:
     // Returns how long it takes to fire
     float GetFireTime()
 

This type of function should be moved to Weapon and called GetAttackTime() or something similar. Each derived class can then override this function with their own implementations to give you the required output.

avatar image staticvoidlol Oct 12 '15 at 07:20 AM

P.S.

Some purists might shoot me on sight for this, but I even put the "Reload" function on Weapon (instead of HandgunWeapon) with an empty implementation, and override this in HandgunWeapon to actually implement it when requried.

This is because Reload is generally something called from outside the Weapon class (e.g. from the Character) and it allows me to not worry about casting when trying to call Reload.

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

0 answers: sort voted first
Be the first one to answer this question
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