test spawn actor in UActorComponent::BeginFrame

Basic question, from a subclass of UActorComponent::BeginPlay is there a way to know if we are on a spawned AActor (versus a level actor)?

The only (non efficient) solutionI see is to combine a UWorld::AddOnActorSpawnedHandler to detect the spawned actor, search for my embedded component.

[Attachment Removed]

Hi,

Here’s a couple of additional approaches:

1.) UActorComponent::OnComponentCreated (When an actor is spawned in the editor or during gameplay, this gets called for any native components. For blueprint-created components, this gets called during construction for that component. This is not called for components loaded from a level.)- You could override that function in your subclass and flag the component when it’s called

2.) You could add a Tag to the Actor when it’s spawned and look for the tag with ActorHasTag

Please let me know if one of these works for you!

Regards

[Attachment Removed]

I’ve built a small project (attached) with a very small plugin containing a native subclass of AActorComponent to validate your solution.

The component UnrReplicationComponentAbstract overrides UActorComponent::OnComponentCreated and prints a log trace.

I’ve used this component in a BP actor called BP_MovingActor and placed some actors in the map.

I’ve enabled and set up World Partition to enable streaming.

In PIE, when I move far away and then come back close, I see that OnComponentCreated is called, which should not be the case in my understanding. Could you have a look at the project and clarify what is going wrong or what I’m misunderstanding?

[Attachment Removed]

I’ve updated the project with a press on the space bat that swan the same actor. It allows to compare the behavior between the spawn and level actor. You can download it here : TestReplication.zip - share.corys.fr

[Attachment Removed]

AActor::IsNetStartupActor() seems to do the job. Thanks to point be some good threads.

[Attachment Removed]

Hi,

I wanted to check-in to see if the above information helped out.

Please let me know, thank you!

[Attachment Removed]

Sounds good but need a final test. Design phase => will be tested “soon”. I’ll keep you in touch here.

[Attachment Removed]

Sounds good, please keep me updated after the test, thank you!

[Attachment Removed]

Thank you for sharing your results.

The difference may be when streaming in and out the actor is being reconstructed.

In this case a simpler approach may be to use deferred spawning and flagging those spawned actors, then finish spawning.

Here’s a thread on that.

Another option would be to utilize RF_WasLoaded according to this thread, but you’d need to ensure the level is saved after dragging the actor in. The thread also mentions AActor::IsNetStartupActor which uses bNetStartup.

I’d recommend the deferred spawning approach where you add a flag, finishing spawning, and then check that flag.

Please let me know if that works for you.

Thank you!

[Attachment Removed]

Awesome, glad to hear! I’ll go ahead and close this case but feel free to respond here if you have follow-up questions.

Thank you!

[Attachment Removed]