Get object by class on begin play doesn't get objects located on sublevels not streamed yet despite being on persistent level

You might need a re-think. You can’t spawn them all on begin play for two reasons:

  1. Your game will hitch really badly for quite a long time

  2. Assuming your stream them out again, the references wont be valid anyway.

You could setup a system which does exactly what you’re doing now, but only does it as the player gets near. So, as the player approaches trees, get their instance numbers and swap them out.

To be honest, I haven’t checked if this concept works, but this vid seems to be related:

Hey guys.

I am making a game similar to the forest, where tree cutting and crafting etc are a major focus. I currently have it all working except for a problem I am having with my Level Streaming and collection of my foliage instances on eventBeginPlay.

Currently on eventBeginPlay I have a function to collect all the tree objects that are spawned by my procedural foliage volume and add them as instances in world space, these are then spawned as my tree static meshes. Then when the player gets close enough to a tree to chop it down, that tree static mesh gets swapped out for my tree actor that I can interact with. It is then swapped back out to a static mesh when I move away from it.

The problem I am having is that not all the objects that I collect on beginplay event are being collected, specifically the ones on different sublevels that aren’t streamed in yet. They stream in as I move closer to them but they obviously miss the collection that happens at begin play so they are not gathered up with the rest of my trees for interaction with later. I have a large map made up of a tile set of 5X5. Each tile has 2 LODs, one streaming in at 50000 and the other at 2 000 000. This is so I can see the mountains in the far distance. I have tried adding my procedural foliage volume to my persistent level thinking that would have them permanently spawned in at begin play but that hasn’t worked and they all still spawn in as the sublevel they are physically located on load, despite them being on the persistent level. I also tried adding them to another sub level that had a streaming distance of 2 000 000 but that hasn’t worked either.

I am just wondering if there is a way to force these objects to be spawned on begin play regardless of which sublevel they are physically located on so they can all get collected together. or if there is an easy way of re-triggering the collect tree function when these sublevels are streamed in.

Hopefully that all makes sense and someone can head me in the right direction.

Thanks in advance
Luke

Yeh i was thinking this was the solution. Just wondering how i can keep track of foliage thats been cut down and turned into a stump etc. Dont want to cut a tree down then have it grown back again after ive gone for a walk over to another sub level and back. Might have to do a little more thinking. thanks for your help