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"

How do you override a primitive component's events on your actor?

I have an actor that has a box component inside of it. How can I override the box's OnClicked event in the same way that I can override the actor's "ReceiveActorOnClicked" event? At least I think that that is the right actor event, I'm new to the C++ side of UE4.

If I were to override the actor's version, I would use this as a signature in the header file -

 virtual void ReceiveActorOnClicked() override;

However, I have no idea how to do the same thing for the box component.

I've attached a screenshot to show which event specifically I'm looking to override.

[1]: /storage/temp/14684-primclick.png

Product Version: Not Selected
Tags:
primclick.png (68.8 kB)
more ▼

asked Sep 06 '14 at 07:25 PM in C++ Programming

avatar image

evillego6
186 20 20 25

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

1 answer: sort voted first

You are right on the actor side, which using you custom actor you just overwrite. For the component you should do the same, create you own component that inherits from the one you use and then you can overwrite it.

In case you want to replace the actor (for example a Pawn or a Character) you have to tell the engine to not spawn the default version of the component so you can take care of specifying your own. Most of the components of the base engine classes are created using 'CreateOptionalDefaultSubobject' so that

This is done passing on the PCIP within your custom actors constructor a function chain telling the super class which components should not get created with its default types, this is achieved using the 'DoNotCreateDefaultSubobject' function. Then in the same constructor you create it using your own using 'CreateDefaultSubobject' to force that no child classes can prevent the creating or using 'CreateOptionalDefaultSubobject' so you could again change the components in other child classes.

An example can be found in the constructors of 'ACharacter', 'APawn' and 'APaperCharacter' which prevents the creation if the character mesh component that comes from 'ACharacter'.

If you have more questions just post them.

Hope I could help!

more ▼

answered Sep 06 '14 at 08:04 PM

avatar image

Moss
6.4k 127 98 606

avatar image evillego6 Sep 06 '14 at 08:33 PM

Hi Moss, thank you for answering. Could you possibly explain the difference between the method that you just suggested and this code snippet in the FPS tutorial in the UE wiki? Specifically this line -

 CollisionComp->OnComponentHit.AddDynamic(this, &AFPSProjectile::OnHit);

It looks like that method could be applied to a component click event as well, right?

avatar image Moss Sep 06 '14 at 08:39 PM

In those you add a callback (a function that you provide) that should be called on the given event. This is used for example in the GameplayAbilities system:

 PrimComponent->OnComponentBeginOverlap.AddDynamic(this, &UAbilityTask_WaitOverlap::OnOverlapCallback);
         PrimComponent->OnComponentHit.AddDynamic(this, &UAbilityTask_WaitOverlap::OnHitCallback);

Using a custom component will give you the ability to do more customized tricks while not changing the behavior on using those events. Using a custom components is far more complicated to setup also.

In my projects I normally use custom components in many cases, so when I need any customization I can do it in less time, but again, this should be considered advanced.

If you just need to respond to the different events (BeginOverlap, Hit, EndOverlap, ...) use the callbacks from your own Actor class.

avatar image evillego6 Sep 07 '14 at 12:19 AM

Thanks a lot, that was an extremely helpful clarification!

(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