I need help getting location of a component from an array of actors.

Okay, I spent some time debugging your project and spotted a few issues.

First, it looks like Return Values from SpawnActor SolarSystemBP_C node are not updating in GalazyBP. So when your HighFloorScale variable is multiplied by 160 to update LastSystemBounds variable, it’s returning 0. That, in turn, means that when you multiply that with anything and then set that as your next SolarSystemBP spawn transform, it will always spawn at 0,0,0.

This looks like a bug. I can’t see any reason spawned Actor isn’t returning proper values. I’m going to dig into this a little further and talk with developers to see if there’s a reason for this or if it is truly a bug that needs fixing. I will let you know what I find out.

way I was able to fix this was to update each of variables that are currently after SpawnActor SolarSystemBP node (Last System Bounds and each of Arrays you’re appending to) by casting to them in SolarSystemBP itself. After each Set HighFloorScale node in SolarSystemBP, cast to GalazyBP and grab variables you need and update them there. It’s easiest to create a function for this and just use that in each of those three spots.

But you’ll still run into an issue with spawning at 0,0,0 for an entirely separate issue: floats have a maximum cap, and you’re reaching that when you multiply GalazySpawn and LastSystemBounds variables to get your Spawn Transform. I saw potential product reach over 11 digits, and I think cap for floats is 10. So when you multiply these two huge numbers together, it seems to be converting that to 0, and you have same problem as before.

I’m going to double check with some programmers tomorrow to see what actual float cap is, and whether this should be converted to 0 or if it should truncate it. Either way, you might need to start using much smaller numbers (or integers, which I believe have a higher cap).

third thing I noticed is that your For Loops tend to start with First Index 0, and then you pass it a desired number for Last Index. I’m not sure if this is intentional, but I figured I would point it out. For example, for your NoOfSolarSystems check, if number given is 4, then it will actually spawn 5 SolarSystemBPs because it starts with number 0 and then goes up to number you gave it.

I’ll keep looking into this, but you can try these workarounds (lowering number scale you’re using, moving variable updates to SolarSystemBP) in meantime to keep your project going. As for ‘Call_Func_Array_Get_Item’ error, I wasn’t getting it at first but as soon as I messed around with Arrays I started getting it. I’ll ask a developer about that, but since it doesn’t seem to actually affect game it might not be a problem.

Would it be possible to get a copy of changes to my BP view Dropbox ? Im trying to recreate way you solve this but I don’t understand how you are casting ? Would really appreciate :smiley:

I dont think for asteroid spawn max float range is being reached though because if you see in SolarSystemBPWorkwithArrayInternaly asteroids spawn, I agree that this wouldn’t work if last system bounds offset system worked but it currently doesn’t

In my new setup i lowered scales a bit, but can still change scale if needed, also another change with an observation

I noticed that If I add say 20000 alongside highfloorscale(which is systems size) to last system bounds then it will only add 20000 each time, not system bounds, so highfloorscale returns 0, this eliminates possibility that variables are too large.
it seems that any vars obtained from spawn actor solarsystemBP doesn’t save if it, but vars do save in solarsystemBP which are created from spawned actors ?

Did some more debugging today and discovered real source of problem, and you’re correct: you’re nowhere near float cap, so don’t worry about scaling everything down.

real problem is that each loop in a Loop macro happens per tick, but Spawn Actor takes longer than that, so things are happening out of order. You set value for High Floor Scale at end of your SolarSystemBP, but Loop attempts next Loop Body before that value has been updated. This causes value to equal zero until after all of SolarSystemBPs have finished, meaning each is spawning in same location.

I know that developers are looking into this behavior with Loops, but my understanding is that it’s not a small adjustment but a fairly complex fix that needs to happen before this will work way we want it to.

I don’t know a way to fix this for your project in meantime, however. I’ll give it some thought and experiment some more. Most likely you’ll need to find another way to set transform for SpawnActor node per loop index. Anything you put before and after SpawnActor inside loop body will run before SpawnActors start, so they won’t be getting correct information from its Return Value, either. For those array appends you’re doing inside loop body, you may need to wait until everything has spawned and do a manual count using Get All Actors of Class.

Sorry that this isn’t working way that it should. Hopefully we’ll get that fixed soon, but I have no timeframe for that yet. I will let you know when we do. Until then, I hope you find a workaround that’s suitable for your project.

Alright thank you, at least we found this issue, I doubt I would have been found if I would have being doing something crazy like spawning a universe haha!

Am I right in saying that this is an issue but only when really pushing engine because that lowers tick Rate?

Just to clarify is there no gaps in my logic then ? Because I’ve been trying to learn unreal for a while (back from udk :smiley: )

This may also explain why system works for spawning asteroids in solarsystemBP but not galaxyBP because workload is much greater and thus frame rate/tick becomes too low to effect setting array/vars?

I may have thought of a work around though, because arrays and vars are issue here with them not being set (thus no locations for spawns, and no ability to cast from other BP’s after spawning an actor from class), there is no major issue with procedural content being created at a slower rate, can adding a delay behind each spawn either in galaxyBP and solarsystemBP or just galaxyBP (though i doubt that solarsystemBP Will need delays because it worked beforehand) this will raise frames rate/tick when processing spawn actor from class, as there is a reduce workload on event begin play because time taken to spawn actors/set vars or array is greater, just a thought ?

If this works I have an idea for partial implementation for your software engineers in that editor can “scan ahead” of spawn actor from class then check if trigger event is an event begin play and automatically add needed delay to rectify this issue.

However above obviously won’t work for tick event as it would cause gameplay problems/ apparent lag which isn’t due to CPU/gpu/internet speed :frowning:

Unfortunately, you can’t use a delay inside a loop, for same reason: loop body occurs each tick. There is a way around this by creating a custom macro that includes a delay, but I already tried that idea and same problem exists. It seems that even with a delay embedded in a custom loop, loop body still performs spawn late.

It’s not a frame rate issue, however, but a weird ordering of loop body elements based on time to perform, I think. Even with a very simple setup that I made this afternoon, in which a blueprint spawns simple blueprint between two print strings, spawn still happens last inside loop. So this isn’t a problem with pushing engine too hard.

And as far as I could see, there’s no flaw in your logic
It’s just a problem with loops inside UE4.

Alright man, just give us a bell when it’s sorted, but why does that altered solarsystemBP which I gave you which spawns asteroids at random planets work then ? It sets arrays and adds to arrays after a spawn actor

Am I still right in thinking that issue here is at galaxyBP and not solarsystemBP ?

ive tried your method of getting loctations from get all actors from class, if i do following in galaxyBP it doesnt work but if i do it in solarsystemBP it works???

do you thing it could be an issue with vars not being passed from from a soawned Bp in a spanwed BP?

Sorry for late response; I was on holiday and then spent most of this last week sick =/

altered solarsystemBP didn’t work in project you gave me, but I didn’t spend much time with it. problems I saw happened with galaxyBP and not solarsystemBP, but I don’t remember seeing a ForLoop inside solarsystemBP and that was root of problem.

Hey bennetherwood,

I was able to speak with one of developers here, and found a workaround for issue here: in your GalazyBP, put a Delay node after Event Begin Play, and set it for something tiny (.001 or whatever). Now your BPs should work way you expect!

It seems that engine needs to finish initializing everything in level at begin play, and so it’s trying to initialize each SolarSystemBP together. By adding delay, everything is initialized before For Loop begins, and it’s able to process each Spawn individually. It has something to do with Actor lifetime, and I’ll admit that much of it is over my head, but my understanding is that this isn’t something that can be fixed without breaking many other things. It should be possible to do with C++ but not with Blueprints, as Blueprints interprets Begin Play as beginning of life for Actors.

Anyway, project as you gave it to me should work way you need it to if you include that brief Delay after Begin Play node in GalazyBP. Please let me know if you have any trouble with it after that!

thanks man but i actually figured this out whilst you were away, i noticed that they spawned at 0,0,0 for a while and then at desired locations, i did it this way.

i also noticed that i can see to get values from this method that didnt work before, maybe an accidental bug fix ?? (in 4.41)

also does adding a delay after an event tick help with peformance because execution just stops or does it still put same workload on system?

thanks

Yup, looks like that’s another way of doing same thing.

It still might be better to use setup your originally had and just add Delay after Event Begin Play node. Even with a Delay, engine is processing everything per Tick. For best performance in general, it’s best to avoid using Event Tick when at all possible.