Change blueprint template values in C++

I have an issue I’ve come up against several times over years developing and I’m curious if there’s any nice solution to this. Say I have a component that I attach to an actor blueprint (in the blueprint template, not a level instance) and IF the blueprint parent class is of a particular type, I want certain properties on the component to change, is there any way to achieve this?

For example let’s pretend I have a primitive component called “UClickBox” and an actor called “UPickup” the “UClickBox” can be added to any actor, but if I add it to an “APickup” I want a bool on (bIsPickupBox) UClickBox to be true, and I want that “UClickBox” instance to change its CollisionEnabled state from QueryOnly to NoCollision.

I could do all of this on begin play, or PostInitProperties, but I want this to be correctly reflected in the actor blueprint, and to hopefully avoid unnecessary gametime logic. I tried doing some logic in the component constructor, but it appears for blueprint templates “GetOwner” is null on components, so I don’t have a way of working out what actor the component is attached to. Does anyone have any possible solutions?

Thanks in advance for any thoughts!

You can not do this with defaults, there only single copy of Class Default Object (CDO) per class and you could make default conditional, but those conditions can only be resolved on load of your C++ module when CDO is created.

You could try to hook up with diffrent virtual functions, look on APIs:

Maybe try RegisterComponent:

You also need to check world type component is assigned to if its EditorPreview

But here problem, if you set this on every component register, this will be trigger on ever asset setup. Maybe seek APIs more you may find some better function to hook up, you can override any “virtual” function even if it does not look like event or have On* prefix

Thanks for the pointers. I had already looked over the virtual functions but at best I get the desired result for objects spawned at runtime/dragged into editor scene but I just can’t get values in the template default values to update (or perhaps they do and they just don’t LOOK like they do in the editor details panel).

I think I understand what you mean about the CDO, but I hadn’t been seeking to change the defaults of the CDO of the component itself. I just want the component values on the blueprint instance used for the blueprint template (I’m unsure if the blueprint template is distinct from the blueprint’s CDO?) In exactly the same way those values would be done if I simply edited them for that blueprint actors defaults in editor, but via code that is happening automatically.