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"

Component made with NewObject cannot be moved

I'm using NewObject to create object that rotate arount it's parent.

 UMySceneComponent* Orbiter = NewObject<UMySceneComponent>(this->GetOwner(), TEXT("OrbigintSubBall"));
         Orbiter->RegisterComponentWithWorld(GetWorld());
         Orbiter->RegisterComponent();

The trouble is that if object is created via attaching in editor, everything is fine. When i'm using NewObject, that thing doesn't move. UMySceneComponent derive from USceneComponent and moving in a tick function by just setting a local position. What's wrong?

Product Version: UE 4.15
Tags:
more ▼

asked Jul 23 '17 at 06:03 AM in C++ Programming

avatar image

6opoDuJIo
1 2 2

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

2 answers: sort voted first

Thats because you did not attach it to anything ;P or at least you left out the Code that would tell me otherwise.

https://docs.unrealengine.com/latest/INT/Programming/Tutorials/Components/1/

more ▼

answered Jul 23 '17 at 06:11 AM

avatar image

Nachtmahr
7k 143 28 172

avatar image 6opoDuJIo Jul 23 '17 at 06:18 AM
 Orbiter->AttachTo(this->GetOwner()->GetRootComponent(), NAME_None, EAttachLocation::SnapToTargetIncludingScale);

or

 Orbiter->SetupAttachment(this->GetOwner()->GetRootComponent());

does literally nothing

avatar image Nachtmahr Jul 23 '17 at 06:24 AM

Can you Upload a bit more Code to www.pastebin.com .h/.cpp and post it here? Would also like to See your Tick Function and how you refer to your Orbiter. Since your Code suggest to me that you don´t store a ref and get a grasp to your Component dynamicly somehow.

avatar image 6opoDuJIo Jul 23 '17 at 06:30 AM

OrbitingObjectSpawnorComponent.cpp : https://pastebin.com/N1iXryhu

OrbitingObjectSpawnorComponent.h : https://pastebin.com/98uY9RqJ

MySceneComponent.cpp : https://pastebin.com/7KzU82k9

MySceneComponent.h : https://pastebin.com/YurcKdMh

avatar image Nachtmahr Jul 23 '17 at 08:20 AM

Hmm Played around a bit. By the looks of it your Component Ticks correctly and does what you expect. The Problematic Part is that it somehow fails to attach your Mesh Comnponent as Child even thoug it shows up in the Hierarchy. Im a little confused myself at this Point. Usually you Create Components from the Owning Actor itself and not via Components.

Tried a coupe ways now restricting myself to Create the Mesh Component from the construction Script. Troublesome xD (btw. you dont need to create a seperate USceneComponent you can use a StaticMeshComponent Directly instead and do your Tick Calculations there)

https://gyazo.com/dbf4293c746b18e07a26c5910dbd370e

avatar image Nachtmahr Jul 23 '17 at 08:39 AM

Oh and by the way if you just want to make it work remove all the stuff you got in the Constructor and do it via Begin Play like this:

 void UOrbitingObjectSpawnorComponent::BeginPlay()
 {
     Super::BeginPlay();
 
     if (this->GetOwner() && this->GetOwner()->GetRootComponent())
     {
         UMySceneComponent* Orbiter = NewObject<UMySceneComponent>(this->GetOwner(), TEXT("OrbigintSubBall"));
         Orbiter->SetupAttachment(this->GetOwner()->GetRootComponent());//does nothing
         //Orbiter->RegisterComponentWithWorld(GetWorld());
         UStaticMeshComponent* Visual = NewObject<UStaticMeshComponent>(this->GetOwner(), TEXT("Visual"));
         UStaticMesh* TheMesh = LoadObject<UStaticMesh>(GetOuter(), TEXT("StaticMesh'/Game/Geometry/Meshes/1M_Cube_Chamfer.1M_Cube_Chamfer'"));
         Visual->SetStaticMesh(TheMesh);
         Visual->SetupAttachment(Orbiter);
         Orbiter->RegisterComponent();
         Visual->RegisterComponent();
     }
 }

Result:

https://gyazo.com/89f5a00a3a3536808d41a37ca3ae9445

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

Seems like I figured out what's wrong. Moved all the "ball creation" stuff into "BeginPlay" instead of constructor and now everything is fine. Seems like if my call stack doesn't belong anymore to "usual" constructor call stack, things can get messy. Lost few hours figuring out what's wrong, but thx for an idea.

more ▼

answered Jul 23 '17 at 08:47 AM

avatar image

6opoDuJIo
1 2 2

avatar image Nachtmahr Jul 23 '17 at 08:48 AM

xD Posted you the Solution right bellow. Guess you figured it out by yourself with the Hint to the Construction script.

(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