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"

Is there a definitive way to have a component of a component in c++?

I am working on creating a variety of nested functionality through components and per-wrapped component trees. For example, I want a component that can bring in a box collider and a text render in the same component.
Which would look like something below with variable complexity.
Actor->[MyCppChildComponent->BoxCollider->TextRender->MyOtherCppChildComponent->etc]
Where everything inside of brackets is handled in c++ and the actor only needs add the component to access all of the functionality exposed, as though the components were all attached in the actor c++/blueprint in a tree, and lots of functionality written into the BP/C++. This seems to me like it could be a modular and elegant way of doing things, but.
I cannot find any engine code component examples of doing this, and every attempt i make winds up causing a multitude of problems for the engine.
Is this simply something UE4 has other ways of doing?
Am I once again treading where Epic's engineers fear to tread?
Is there a way I can get a definitive slap in the face that says: "No! Bad Spiris! This is how you do it..."?

Product Version: UE 4.11
Tags:
more ▼

asked May 10 '16 at 05:25 PM in C++ Programming

avatar image

Spiris
1.1k 40 33 76

avatar image Univise May 11 '16 at 04:30 PM

You might want to get into scene components. Those can have child components, which have children added, removed, and modified in the level editor. However, scene components are designed to display some type of scenery in the world, though they needn't. You must just make a design choice which consists of trade-offs that are specific to your project. Remember though that in engineering there is never the best option: it is always about the trade-offs. So good luck to you.

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

1 answer: sort voted first

Hello Spiris,

USceneComponents can have other USceneComponents attached to each other as children; those children can be modfied in the details panel of an object.

The Unreal documentation describes them as:

A SceneComponent has a transform and supports attachment, but has no rendering or collision capabilities. Useful as a 'dummy' component in the hierarchy to offset others.

In the link you can find methods for modifying children. The most important you will be using are GetChildrenComponents and AttachTo.

In the approach you mention, it makes sense to define some public interface for all components that you want to be using in a modular way. However note that scene components generally speaking are supposed to show some scenery. As you are trying to add configurable modularity to your project: I once had the same task at hand and I can provide you with a way I solved it - below.

You create one actor component that adminsters the entire system you are currently implementing; let's call it UMySystemComponent. To it you can add modules. When an actor wants to use your system, you add the component to it and add specific modules. To define a module let's create a class, I will call it UConfigurableModule for reference, that defines the basic interface required by any module, for instance a UFunction named Callback(); UConfigurableModule should inherit from UObject from a design perspective but due to engine bugs (which I reported here) it must temporarily inherit from UActorComponent until it's fixed. The class specifiers of UConfigurableModule shall be Blueprintable, BlueprintType and EditInlineNew. In UMySystemComponent, add a TArray as property and make sure it has the specifiers EditAnywhere and Instanced. Now, your level designers can specify classes for components in your UMySystemComponent and configure their propertiers right in the details panel of UMySystemComponent. Da-da

Cheers, Univise

more ▼

answered May 12 '16 at 09:01 AM

avatar image

Univise
201 9 10 22

avatar image Spiris May 12 '16 at 04:37 PM

An elegant and effective solution! I am compiling my notes on the topic now, maybe I will post a google doc about the knowledge I have gained. Thanks Univise.

avatar image Vlady Veselinov Jan 08 '18 at 10:12 AM

Isn't AttachTo deprecated?

(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