As the title says, I spawn an ActorComponent in the BeginPlay() of my actor with the NewObject.
I need to search the components of my actor during runtime and I cannot find this ActorComponent using the Actor->GetComponents function. The ActorComponent is running normally. I also use the RegisterComponent() function after spawning.
I tried the CreateDefaultSubobject method in the constructor and it works fine, but unfortunately I cannot
spawn it this way for technical reason.
I tried to reproduce the behavior you reported by creating a new class and adding a couple of default components to it. Then in the begin play function I added the following code:
GEngine->AddOnScreenDebugMessage(-1, 4.f, FColor::Blue, FString::FromInt(Components.Num()));
GEngine->AddOnScreenDebugMessage(-1, 4.f, FColor::Red, FString::FromInt(Components.Num()));
After compiling and adding an instance of the blueprint based on this class to the level it printed 2 in blue (the default components added in the constructor) followed by 3 in red. This seems to me that GetComponents is registuring the newly added component. Can you confirm if you see the same result with this setup? Also, can you provide the code for your actor class so I can see how my setup differs from what you’re using?
We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.