EvilTurtleProductions Posted April 5, 2022 Share Posted April 5, 2022 In my procedurally generated levels I want to be able to turn lights on or off when, for example, the power goes out and thus all lights need to go out. The level is generated from CFG prefabs, which are then decorated with models and lights. The lights are parented to the CFG prefab. But I've been struggling with a strange bug, it seems only half the lights in the level go out. I've tried using SetIntensity(), SetColor() and Hide(). I've also tried unparenting, reparenting or not parenting at all. All create the same result. In the screenshot it's clearly visible: there are four lights close to the floor, two to the left, two to the right. When the lights are turned off the ones on the left indeed go off, but the ones on the right still seem to be there? Any suggestions what this could be? I'm quite lost right now. Is there some limit I'm hitting (there's about 100 to 200 lights in a level)? Quote Link to comment Share on other sites More sharing options...
Josh Posted April 8, 2022 Share Posted April 8, 2022 Will need a demo to debug. I strongly suspect the lights aren't really being hidden, and there is an error in the programming. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
EvilTurtleProductions Posted April 9, 2022 Author Share Posted April 9, 2022 On 4/8/2022 at 12:29 PM, Josh said: Will need a demo to debug. I strongly suspect the lights aren't really being hidden, and there is an error in the programming. I've made a simple demo, replicating the way the game builds levels (albeit just one node in this test) and modifies the lights and I get the same issue. See attachment for the project. All the code is in C++, I've commented it heavily so hopefully that is some help. The prefab objects are in the Prefabs folder & in the editor in scene/prefabs. LightsTest.zip Quote Link to comment Share on other sites More sharing options...
Josh Posted April 10, 2022 Share Posted April 10, 2022 So, what do I do? It's just a hallway with a few lights. What is supposed to happen? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
EvilTurtleProductions Posted April 11, 2022 Author Share Posted April 11, 2022 13 hours ago, Josh said: So, what do I do? It's just a hallway with a few lights. What is supposed to happen? After about 4 seconds two of the lights go off, even though I set all four lights to go off. Check the code comments in App.cpp. 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted April 12, 2022 Share Posted April 12, 2022 I know why this is happening. //find lights in the primary decoration for (int i = 0; i < dec_prim->CountChildren(); i++) { Entity* findlights = dec_prim->GetChild(i); if (findlights->GetKeyValue("name") == "Light") { //parent the light findlights->SetParent(node); // Hmmm, do you think COuntChildren) will return the same result next time i call it lol??? } } 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted April 12, 2022 Share Posted April 12, 2022 You can replace that loop with while (CountChildren()) and always get the first (0) child. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted April 12, 2022 Share Posted April 12, 2022 Also, I recommend you hide the light instead of just setting the color to black. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
EvilTurtleProductions Posted April 12, 2022 Author Share Posted April 12, 2022 Big dumb moment there. I was staring at the wrong problem, haha, thanks. I implemented a different solution than the while loop though, since not all children might be lights. Instead I use a vector that I fill with all the lights, then loop through this vector to re-parent the lights. 1 Quote Link to comment Share on other sites More sharing options...
EvilTurtleProductions Posted April 12, 2022 Author Share Posted April 12, 2022 Just now, Josh said: Also, I recommend you hide the light instead of just setting the color to black. Yes. I was planning this for lights that are completely off. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.