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"

Most Optimal Method for Unlockable Abilities?

There is a system in my game, where as you progress through the game as well as by gaining levels, certain abilities will unlock. However, I am having a hard time deciding if I should go about doing this with an array of booleans or if I should make individual booleans for each character and turn them on/off. However, I am not sure which is the most optimal or the most preferable. Or maybe there is an even better method, that I am not aware of. Was hoping to hear some feedback as to how some would approach this method.

Product Version: UE 4.19
Tags:
more ▼

asked May 09 '18 at 07:50 AM in Blueprint Scripting

avatar image

Dylanrockin
1 3 6 12

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

1 answer: sort voted first

Create a master Ability blueprint - an Actor Component. Encapsulate logic and variables all abilities share.

  • enabled, stats, range, damage, duration and whatnot

  • functions/events/methods for Use, Cooldown, Upgrade and so on

  • visuals for the abilities

  • anything else you need

Create a child for each ability providing they need unique functionality. Give the player character all abilities but keep them disabled. Enable as needed.


The following video is a foot in the door of the components how-to:

https://www.youtube.com/watch?v=qr4ZjieAQKY

more ▼

answered May 09 '18 at 09:48 AM

avatar image

Everynone
13.7k 74 25 57

avatar image Dylanrockin May 09 '18 at 10:16 AM

Huh, I'm assuming this is the much more optimal choice, instead of me storing away a bunch of booleans into ThirdPersonCharacter and activating them based on some criteria? And when you say encapsulate logic and variables all abilities share, do you mean have all the variables and logic be shared across all abilities?

avatar image Everynone May 09 '18 at 10:29 AM

Yes, that's the core of OOP.

Creating a new ability will instantiate the variables and logic for each component. Each will have its own values, and can have its functionality triggered separately.

Surely, you'd rather avoid creating identical variables and writing the same code for 20 abilities.

Have a bool (isEnabled) in each component to figure out whether it can be used.

You could store it in the player's blueprint, sure. You could pack it all into a single blueprint but you'll be creating a lot of work for yourself in the long run.

Imagine what happens if you decide that each ability needs one extra variable. You create another 20 variables in the Player Character? Nah, go the the master ability blueprint all abilities inherit from and add 1 variable, compile. All abilities have 1 extra variable for you to fiddle with.

edit:

You can see inherited variable here:

alt text

capture.png (72.3 kB)
avatar image Dylanrockin May 09 '18 at 09:10 PM

So, ideally I should also have my character's stats in a separate component as well? Should I also have damage calculation and my level up calculation in it as well? Sorry for all the questions, I am relatively new to how UE4 handles OOP. I am more used to RMXP and how it handles classes, so I'm still trying to get to grips with things, haha.

avatar image Everynone May 09 '18 at 10:14 PM

Think of components as chunks of reusable behaviour you can grant to any actor. Even if you have 5 completely unrelated classes that do need to share some kind of behaviour (like ExplodesOnDeath), having it in a component will simplify things. Components are about making things modular.

So, ideally I should also have my character's stats in a separate component as well?

Are you going to re-use those stats anywhere else? If no, there's probably no need to create another module to handle player stats. If multiple object classes need the same stats, you can wrap them in a GeneralStats component.


Should I also have damage calculation and my level up calculation in it as well?

If you're going to need those in other blueprint classes then wrapping damage calculations in a component might be a good idea. Let's say you've got 5 classes in your game:

  1. the player

  2. a vendor

  3. an enemy

  4. a questgiver NPC

  5. a trapped chest

These will vary quite dramatically when it comes to the in-game behaviour, but 1,3 & 5 will be dealing damage. You can give those three a DealDamage component which can pull the stats from the owning class' GeneralStats and deal damage accordingly.

1, 2 & 3 can be given a LevelUp component that tracks the experience points (stored in GeneralStats) and increases the level of this class by pulling data out of a the appropriate DataTable.


You do not need to use components at all. You can use classes exclusively. But sprinkling it with component magic can make things easier.

avatar image Dylanrockin May 10 '18 at 12:27 AM

I intend to have multiple characters have different stats, based on their play-style, so I am not entirely sure if I should have it be associated in there, rather than have it be in its home with the ThirdPersonCharacter. But, again, not entirely sure, since not every character will have the same growths and the same stats.

I can see all of that being super useful, but I am mostly just worried about my Event Dispatchers and how I'd call them in the components to do certain things. Because there were some aspects of my blueprints that made use of Event Dispatchers and now they don't work in my Components.

(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