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"

Reference to a component for another component

Hey, community

So, I've decided to become the ue4 guru, but I've stuck at the beginning :( Keep in mind following

 class UCustomMovement : public UActorComponent
     UPROPERTY( Instanced, BlueprintReadWrite, Category = Impl)
     UMovementComponent* Movement;

In a character editor I'm creating this custom movement and movement component. Here's the issue: I want to pass a reference of this movement component to my custom movement, but I can't find a way to do this.

I've been developing using Unity for some time, hence the behaviour I want to get is a SerializedField property.

Patiently waiting for a master to help soon-to-be-master :)

Product Version: Not Selected
more ▼

asked Jan 22 '15 at 04:05 PM in C++ Programming

avatar image

31 3 5 7

avatar image falola Apr 22 '15 at 03:11 AM

I'm still trying to figure this out as well

avatar image CanisLupus_ Jul 04 '15 at 02:26 PM

I should add that I'm also looking for this. :)

avatar image Alyph Aug 28 '16 at 09:26 PM

I'm also interested in this. I didn't want to go through the event graph because I want those references be set in the property window. So far all I can do is set the component's name and wire the references in code.

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

3 answers: sort voted first

You mean something like this?

 Movement = Cast<UMovementComponent>(GetOwner()->GetComponentByClass(UMovementComponent::StaticClass()));
more ▼

answered Jul 04 '15 at 02:54 PM

avatar image

6.8k 333 185 470

avatar image CanisLupus_ Jul 04 '15 at 03:29 PM

I think that what vivalavladislav was trying to know, based on the mention of Unity's SerializedField, is if it's possible to add a reference, in the Details panel, to a certain component that belongs to a world actor.

I was able to do it by declaring a reference to the actor and the type of component to get.

 ACustomActor* ActorReference;
 TSubclassOf<class USceneComponent> TypeOfComponent;

These should now appear on the Details panel. Then, based on your GetComponentByClass suggestion, I did this:

 UCustomComponent* comp = Cast<UCustomComponent>(ActorReference->GetComponentByClass(TypeOfComponent));

It works! :) However, I'm still looking for better alternatives and perhaps a way to get a specific component reference if an actor has multiple components of the same type (like colliders). I wish to avoid getting all such components (using GetComponentsByClass) and then using their string names to differentiate them, though that might not be possible...

avatar image eXi Jul 04 '15 at 03:39 PM

Ok, but basicly you are getting the Component of an actor with the mentioned function. I have no idea if this can be done in another way. I'm getting my component refs like this and it works well :O But for now i didn't need to get a component that exists more than once on an actor.

avatar image j_zeitler Dec 01 '16 at 12:23 PM

I think this is the correct answer. i.e. the requested functionality does not exist but can be mocked to some degree. I'm also looking for a solution for exactly the multiple collider case.

avatar image virtual_method May 18 '17 at 08:34 PM

Just to add a little explanation to this for beginners: You create both variables (actor and component references). The component reference is not an particular instance, but after executing this you will have to find if that actor has that type of component or not.

If you want to do it just with "actor" and not asking for a component type, I suggest you call the same to get "comp" but instead of TypeOfComponent, you call YourComponentClass::StaticClass(). You can't use "YourComponentClass" name directly on GetComponentByClass.

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

Don't know if you've found a better way, but I do it through setting the reference manually using BP nodes.

For example, in my BeginPlay event, I manually get a reference to both components, and then use the "Set [Name of Variable]" node and pass the reference. I'd love for metadata to be able to describe where to find the component and allow direct setting in the details window, but that's a good workaround.

Edit: Oh yeah, you might also want to mark the property "VisibleAnywhere" so that you can't set it to something invalid from the Details panel.

more ▼

answered Sep 21 '15 at 05:12 PM

avatar image

251 21 25 191

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

answered Jan 25 '18 at 01:38 PM

avatar image

199 9 15 18

(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