When I create a component in C++ from my actor, when I spawn a blueprint on the level (in editor as at runtime), relative location is broken and my component is placed at 0 0 0 world location, I need to reset relative location to make it retrieving default location.
It is embarassing when I want to place a component with an offset if created in C++. I saw this issue since UE 4.10 (may be the issue is present in older versions too, I not checked it) and I am currently on 4.12.5.
Is it a bug or I miss something with initialization ?
I do not set relative location in code, I just move my component in blueprint edior viewport. And when I place blueprint on level the component is just placed far away.
I have looked into your issue and I am not seeing anything wrong when attaching one component to another, after creating a AActor in C++ and editing the components when creating a Blueprint child class of the AActor.
Here is the code for creating the components and how I am attaching one to another:
Hey, , sorry for bothering you, can you possibly take a look at this question? Contents of StaticMeshComponent disappear upon changing ChildActorComponent - Programming & Scripting - Epic Developer Community Forums it has the same symptom, child actor that i’m attempting to use in that question actually was created through c++ and has same symptom as in this question, and using this child actor causes parent pawn to break. I will actually try attaching them in the way you posted here, maybe that was a reason of this havoc, but anyway it doesnt look like expected behaviour… something shady is going on there.
btw, AttachToComponent didnt fixed anything for me, i’m creating component pointers in the same way, except i’m setting their actual mesh and ps data in derived blueprint class. When i drop it in to level particle system still spawns at 0.0.0 while mesh(root) spawns at dragged location. Particle system does move around with mesh though retaining initial distance between them.
And it does not seems to be issue with ps or mesh - if i recreate same thing as pure blueprint class - everything is attached correctly.
Can you explain exactly what you’re doing and the behavior you’re getting? Particularly, what is setup in code and what is setup/changed in blueprints? If you’re able to reproduce this, can you provide the setup steps you’re using?
Sure, the same way as in this answer - i’ve set up UParticleSystemComponent* and UMeshComponent* in .h, initialised them through CreateDefaultSubobject in class constructor in cpp and set . That’s it. I was not setting actual mesh or particles asset in c++, instead, at this point, i’ve created child blueprint from this class and set mesh/ps on components through bp interface. Adding particlesComp->AttachToComponent(meshComp,...) in class constructer and\or in beginPlay did nothing. As soon as i drag bp class in to a view and drag it around (wihthout dropping it yet) i can see that only mesh being dragged around and ps is still spawned at 0.0.0. If i’ll drag it around after i’ve dropped in to view, both components will change their global position but remain the same initial broken relative one.
Thank you for submitting a bug report. I have reproduced this issue and logged a report for it here Unreal Engine Issues and Bug Tracker (UE-40054) . You can track the report’s status as the issue is reviewed by our development staff. Please be aware that this issue may not be prioritized or fixed soon.
Thanks, , glad that it’s at least in bug tracker now.
Also i’ve noticed in description of bug you specifically mentioned " if AttachToComponent / SetupAttachment / etc. is not expressly used from code" so does using AttachToComponent actually fixes issue for you? Cos for me with this setup AttachToComponent has no effect.
That’s correct. When I add TestParticle->AttachToComponent(RootMesh, FAttachmentTransformRules(EAttachmentRule::[AnyRule], true)); to my constructor and compile, new instances of the class/child blueprint will have the particle system attached at the root actor’s origin. Without this line of code, I saw the same behavior you described.
Can you elaborate on what is happening in your case? Can you provide the code used that shows this behavior? Are you using SetupAttachment to attach your component to the root component of the actor?
Hi, I’m having the same problem right now.
I overrode OnConstruction() and I’m calling a function there, which creates ChildActors, attaches them and SetRelativeTransform().
It appears you’re adding a component to the actor as it’s placed in the level / spawned. If the component will always be created as part of the actor, it would probably work better to add the component in the actor’s Constructor rather than OnConstruction().