I am trying to make a simple system. I would like for the sun to rotate depending on the number of enemy AIs are still on the battlefield.
i.e 10 demons = Night Time
0 demons = Day Time
So I created a float and a conditional branch - but am having trouble casting from my AI character blueprint - to the level blueprint.
How do I cast to or affect a situation found in the “level blueprint” from a character/actor blueprint? I made a variable that says when it is >= 10 - the sun rotates (in the level blueprint) - and I would like to alter that variable from another blueprint. Is this the right approach? Should I create a separate blueprint for this action? Or make a separate blueprint using the Light Source?
Any guidance would really really be appreciated.
At the end of the day - my end goal - is to have the world be set at “night” when there are demons - but when they player kills them all - it turns into “daytime”
I took the time to go through the entire process you’re trying to complete, to some degree. I’ll show you how to reference variables across blueprints, in the scope of what you’re attempting to do.
I started this entire thing with the Blueprint style First Person Shooter template on a new project. First thing was to add a Point Light and add a blueprint to it, this will simulate your sun. I then added the following nodes to the Event Graph of the point light’s blueprint:
I made a branch to go from the tick so that it would be checked every frame. I then added a bool to determine if the sun should turn on or off. I’m sure there are other ways to control it being on or off, but for this I was using intensity. Be sure to set the boolean to public by clicking the closed eye icon on the left side of the editor.
I then moved onto the FirstPersonCharacter blueprint and ignored the blueprints that were already there. I added the following nodes.
I used left mouse just as something to increment and added an int to count how many ‘demons had been slayed’ (This can just be incremented on their destruction.) I then added 1 per click, checked to see when it became greater than 10, then set the boolean from the PointLight to false. Didn’t think about it til after, but this is the opposite of what your game will do. It should show you how to get this done however.
Be sure that if you decide to do it exactly my way, that you set the PointLight variable in the blueprint to the correct object and also set it in the FirstPersonCharacter’s variables in the project view, otherwise it’ll fail to reference the variable every time. You should also be able to add a branch somewhere in the FirstPlayerCharacter’s blueprint to switch the light back on using certain conditions.
Hope this helps! If it doesn’t, let me know and I’ll be happy to help more.
Wow! Thank you so much for taking the time to do that. It is almost a perfect system I am looking for - the only problem is - I want to control the “directional source” (the sun) not a point light. - So I tried doing this - by creating an actor blueprint and called it “Changing Sun” - and pretty much followed the logic here - and it works - but something is missing from it. I think I need to update the sky sphere to reflect my new creation. Not sure - I will have time later today - to post my findings and some screenshot. When done correctly - I think I am going to try to make a tutorial! As it is a cool feature that I hope a lot of people will benefit from.
Thank you so much for your hard work! It means a lot to me -
Is it possible to cast to a level blueprint from within a character blueprint - i.e - my AI blueprint? That would make life a lot easier -
I do not believe that it is possible to cast to the Level Blueprint, trying at the moment of typing this I’m unable to even access a public variable that is made in the level blueprint from an actor blueprint. Good luck if you plan to make a tutorial. Feel free to post it in the comments here if you do, I’m sure it’ll help a lot of people.