I dont think i will get any answer, think i have wroted 4 times questions and never had any answers. But i try again anyway.
This time my problem is this. I have made 1 persistent level with some basic lightning and so…and i have 2 streamed level.
On 1 of the streamed levels i spawn a 5 cube meshes (from another blueprint class), i do that from that streamed levels “level blueprint”.
Everything works fine with the streaming but the cubes does not disappear when i leave the streamed area, instead when i walk in and out they doubles each time.
how can i make the spawned object also disappear when i run out from that streamed level?
In this case you should handle the level loading yourself. When you trigger the level to load and the items spawn, save a ref to each spawned object in an array. When you trigger the unload, run your spawn ref array through a for each node destroying the actors. Then off the Completed pin of the for each loop clear the array so it is clean for the next world load.
If needed I can mock this up tomorrow and attach a picture.
Thanks for answering, i was also thinking about the same idea but i tried and tried but could not figure out how to do it. I am still beginner in unreal then. What do you mean by handle the level loading myself? can i control it from bp?. i send a picture of the level bp i made for spawning the cubes. Would be very glad if you could make a example.
you mean that i should use box trigger instead of the built in function where you can set distance for level stream? or how does it work? i try search google but not so much information…
A box trigger will work for this. So when you leave the level it unloads and destroys all boxes you’ve created. However, an easier option for you would be putting the boxes in the level to be streamed in instead of spawning them in after load. That way the meshes are contained in the level and will appear and disappear on load and unload. Why did you have them spawn in after load? Is there a specific reason for this?
Thanks for your reply. When you told me this i started to think about it myself why do i let them spawn from an array when start play, you are very right
its much more easy just to drag them one by one into each level, and they delete themself when i unload it :). Well i think i do it the way you told me instead. I am just try to learn Unreal by making a world with some simple cubes i can attack that respawn after some seconds when they been destroyed, and all that stuff work fine. Lol i feel stupid why i did not think about making it more easy and just drop them on the level :D. Well i guess thats the way to learn some times :). Glad for all response. Thanks allot.
But i think i still need to destroy them in some way, cause when i attack the cube and it respawns after a few second and i after let the level unload the cubes are not gone :D. So if you want to help explain how to do that i am happy :). I will try to find it out but glad if you want to help.
What i tried so far on the level where i want my respawned cubes to be deleted when the leve is unloaded is that i cant delete them on “end play”, then i am not using trigger boxes, i use the built in distance for streaming levels. So maybe the only way is using trigger box and before i unload the level i destroy the cubes?. would be glad for help
I will try explain more clearly what i want to do, and what i have done.
I have made an actor blueprint with a destructible mesh cube inside it, and in that blueprint i also i made it to re spawn 10 seconds after it have been destructed.
Then i have 2 streamed levels (wich i not have used any trigger boxes inside, only the default settings with distance instead of trigger boxes).
And then i have the persisted level with only some light, fog and stuff.
Now i dragged and dropped my actor blueprint on different spots on 1 of the streamed levels, so i can attack the cubes.
When i start playing around and walk in and out from the level streaming limit, it works nice and the cubes disappears and all the rest of the unloaded level :).
But the problem starts when i have attacked a cube and it have re spawned, and i once again walk outside the distance limit and let the level unload, everything unloads but not the cube that was re spawned.
How fix this? and hopefully without trigger box?
I tried many things and i am also new to unreal so i would be very happy for answer on this :).
For example can some one tell me how do i destroy the cube from a level blueprint? i tried “cast to” but get confused how to use it.
There are many different ways that you can go about doing that! Once I’m at my PC, I’ll throw something together really quick for one possibility that could work and it would make the cubes be a constant within the level.
Actually, that’s exactly what I was going to recommend lol. To store what cubes are actually there, you could make a Blueprint Struct with the Cube Array reference, and a transform array reference to store what cubes are still there. Whenever a cube spawns, add it to the array of the structure, and add it’s actor transform there, as well. If they are static, that will store it’s location, rotation, and scaling as well as it’s actor name. Then when you go to destroy the actors, bring the structure into the GameInstance and drag the key on the right out and break it so you have the array and transforms separate. Then to destroy the actors, use a for each loop to destroy all actors in the array that you stored. That way it kills only the ones that are actually there, and you also have them stored so you can spawn them back in once everything loads back in. That SHOULD work, but since I’m not at my PC, I can’t really test it. Let me know how it goes.
i think i am on the way solving it :D, i use a game instance where i make a array where i store all spawned cubes (just like Pariah013 said), and on my level bp i use “event end play” and cast to my game instanc, and destroy the cubes i just need to figure out how to control what cube still there so it dont try to destroy something that is not there :), well if there are better ways please tell me, maybe i do this way to complicated?
Ok thanks allot for that answer i am not sure i understand perfectly but i will try
if you want to show on a picture of blueprint i would be very happy to ofc :P. When you are at your PC. I just started with unreal a few month ago, so trying to learn :).
I added you on the editor interface, so we can chat over that and I can explain it a bit better.
How are you handling the destruction? I see that it’s a bool variable, but how is it executing?
ok thanks not sure how that works then but i guess that will show :). I add a picture of the cube actor blueprint and some of whats inside it. The test array is then from the game instance a reference to “slasktratten” (the cube actor bp).
It works nice and every new spawned cube will have its name in the array, like slasktratten, slasktratten1…but now i am thinking of if i could just get the name of the fractured cube and just delete that post from the array, but i am not sure how to get the name of the fractured cube :D.
Cause in the same blueprint (slasktratten) i have “oncomponentfracture” event wich handles the destroying of the old cube and re spawning of the new one. On the picture you see the end of that event. How can i get the name of the fractured cube? i mean like slasktratten1, slasktratten2…and so on.
it is just a simple collision with the character and the cube, well i added some damage points and so on. i add a picture of the beginning of this…i see i have a some crap in this now but trying to experiment how to get the name of the fractured cube right after ondefracture event.
This is not really a serious project, just learning so i have used some not very logical names and so on on the variables and the comments lol but hope you understand :).
Hah! I do, indeed! Still going to fiddle with it and see what I can come up with myself since it’ll help us both out. I’m on now, btw if you want to hit me up on there.