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"

CreateDefaultSubobject confusion

I have a Lamp actor like this:

.h

 UPROPERTY(EditAnywhere, BlueprintReadOnly)
 ULightComponent* lightSource;

.cpp Constructor

 lightSource = CreateDefaultSubobject<ULightComponent, UPointLightComponent>(TEXT("Light Source"));

When I drag a Lamp actor onto the stage, its properties panel includes a dropdown that seems to allow me to select a different light component type:

alt text

However, if I select any of it (say a Spot Light for this example), a new component appears at the bottom of the tree:

alt text

And I can't edit it:

alt text

At this point, Light Source does point to a SpotLightComponent--if I debug, I can see that the lightSource variable is now of that new type, meaning it is technically a UPROPERTY in c++, contrary to the error message above. However, it displays as an uneditable, extra component in the editor.

What I expected was that selecting SpotLight from the dropdown would replace the point light I had before; it wouldn't be added as a new component, it'd replace and be called lightSource in the child components tree, and I would be able to click on it on said tree and edit as normal.

Questions:

  1. What is the point of the dropdown?

  2. How can I write the class so that I can replace the light type cleanly as described? As it stands right now, there is no point in storing a ULightComponent* when I can't actually take advantage of that abstract base.

Product Version: UE 4.8
Tags:
dropdown.jpg (77.2 kB)
newcomponent.jpg (21.7 kB)
errormsg.jpg (45.6 kB)
more ▼

asked Aug 04 '15 at 04:48 AM in C++ Programming

avatar image

sgp
151 32 38 55

avatar image Raikoh Aug 26 '15 at 09:24 AM

I got this thing too, it's annoying, i think it's a bug.

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

1 answer: sort voted first

Try removing specifiers from UPROPERTY(), as hind text tell you, you just need UPROPERTY() so engine can see varable, not to make it EditAnywhere

more ▼

answered Aug 26 '15 at 02:25 PM

avatar image

Shadowriver
34.6k 917 164 1095

avatar image Raikoh Aug 26 '15 at 02:30 PM

Yeah you are right, i switched from EditAnywhere to VisibleAnywhere and it works like i wanted. Sometimes it happens to confuse the two and then weird stuff happens :)

avatar image sgp Aug 28 '15 at 03:51 AM

I tried this but did not get a dropdown to choose my desired light type from at all. Can you post the relevant code/screenshots of how it looks like on your end?

avatar image Raikoh Aug 28 '15 at 10:53 AM

Hey, i just looked and ULightComponent is an abstract class, it's the base class for the lights components (DirectionalLight, PointLight, SpotLight). So you need to use for example :

UPROPERTY(VisibleAnywhere, BlueprintReadOnly) UPointLightComponent* lightSource;

and it should work fine.

avatar image sgp Aug 28 '15 at 05:26 PM

Thanks for the help, but it really makes no sense--I want to be able to choose whether the component is a DirectionalLight/PointLight/SpotLight in the editor, so it makes sense to use the abstract base. Tried using UPointLightComponent* anyway but it didn't work. Are we perhaps looking for different behaviour?

avatar image Shadowriver Aug 28 '15 at 06:23 PM

Then use TSubclassOf and with code initiate right type of component based on that varable

avatar image sgp Aug 28 '15 at 03:50 AM

I removed all the specifiers from UPROPERTY(), but the result was that I don't get a dropdown at all--I don't get to choose my desired light type. What do you mean by "as hind text tell you" by the way?

avatar image Shadowriver Aug 28 '15 at 06:25 PM

Then use TSubclassOf and with code initiate right type of component based on that varable, you would need to do that on runtime thru, which will make component uneditable. Also don't place any LightComponents in base class if you have any

avatar image sgp Aug 28 '15 at 07:32 PM

It needs to be editable, there is no meaning if it's not. It just doesn't make sense why I get a dropdown when I can't work with it in any meaningful way.

(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