How to find and use components generically in Unreal C++ - FindComponentByClass - UE C++ Tutorial

preview_player
Показать описание
Actor components allow you to build modular gameplay features that can be mix and matched.
Often it is better to add a component, than create a new subclass of an actor.
It is easy to get an arbitrary component from an actor, even if it is added in blueprint.
There is the FindComponentByClass function, which allows you to iterate over the owned components to find one of the type you are searching for.
There is also the GetComponents function, which returns all the components of a given type in an array.
That is useful when there may be multiple components on a actor, such as with skeletal meshes.

0:00 What's an actor component?
0:14 Making a fake health system component
0:27 Adding code components to a blueprint actor
0:46 Using a console command to test acquiring a component
1:14 FindComponentByClass explored
1:35 Debugging FindComponentByClass via a console command test
1:53 Why you should prefer components
2:10 Looking at how FindComponentByClass works
2:25 How the ability system gives an alterantive to FindComponentByClass, AbilitySystemInterface
3:10 GetComponents functions is the plural version, returns multiple components
3:17 TInlineComponentArray explained, it has preallocated elements on stack
3:40 Adding skeletal mesh components to actor
3:58 Testing GetComponents function
Рекомендации по теме
Комментарии
Автор

I had to reupload this one, because I had accidentally uploaded the draft version last week!
in the previous upload, falra_erisian pointed out that:
With TInlineComponentArray you can use a constructor with Actor and make it in one line like this:

Components(Actor);

enigma_dev
Автор

Thanks for another video, really enjoy your content. I have a question about the hierarchy of components.

If I have BP-C++ class, in which hierarchy is it better to create components if the component is created from C++ class. In BP class hierarchy or in C++ class hierarchy?

In another tutorial I saw an advice that if there is a BP class, it is better to create all components in the BP class hierarchy. It was also said that it is better not to change BP class hierarchy directly, but to create a separate own C++ component for this purpose. And attach all new components to it.

I would like to know your opinion on this issue.

darkshoker
welcome to shbcf.ru