[SOLVED] Cannot Set visibility of objects in Game mode

Hi everyone.

I looked in the forums and still couldn’t find a solution. This thing looks supersilly to me but I cannot make it work.
So I have a simple function inside a blueprint to toggle the visibility of all lamposts in a scene.
It works perfectly in the editor but when I hit Play, it doesn’t.
However, if I try to print the actors from GetAllActorsOfClass, it actually prints them. Still the ToggleVisibility function does nothing.

Anyone can help me, please?

This is the blueprint:


When you’re using the Get All Actors of Class node you seem to be getting Spot Lights. Is there a particular reason you’re using a Toggle Visibility on a Root Component?
You should be able to drag out the Array Element from the For Each and attach the Toggle to that, I believe.

Are these Spot Light actors just Spot Lights or are you trying to Get All Actors of a Blueprint Actor that you made?

Hi man , i quickly made a test with an “event”, and it works fine ,

Hi Jason.
Thank you for replying.

I need to use the root component, otherwise it says it’s incompatible (“Spot Light Object reference is not compatible with Scene Component Object reference”). Actually the root component node is added automatically when I link the array element to the ToggleVisibility target.
I added a lot of spotlights on a road, so thise are the actors I want to get. They are standard Spotlights.

Another thing I noticed is that when I’m in play mode, if I previously select a spotlight, the value of “Visible” actually does change! But it doesn’s show in the screen. So the value of Visible turns on and off but the light is the same. However the light does torn on or off in the Editor (not play).

Maybe there’s a refresh thing? I know it can be done but for some reason I can’t do it. I had “use less CPU when in background” disabled because I’m using web remote. I turned it on again but still the same results.

Thank you!

Thank you for trying, Est_engine. Did you try in play mode?
Maybe it’s some setting causing a conflict with the viewport.
I’ll start a new scene from scracth. I have the feeling it will work, but then why it doesn’t work now?

I tested Est_engine’s Blueprint using Play and it works. Additionally, I created my own using Spotlights…

This is in the ThirdPersonGamemode and it works in the Editor, in Play, and as a Standalone Game.

One thing to note is that I was not given the option of using a Root Component. When I dragged out from the Array Element pin, I chose ToggleVisibility(Spot Light Component).

How did you actually get the Root Component reference?

Also I have two questions:

  1. When you say that it works perfectly in the Editor, how are you testing that? Are you hitting “Simulate”?

  2. It seems your Toggle All is a Function. Where is this Function being called? Are you sure that the function is actually activated when you hit Play? In other words, do you have an Event Begin Play Node in your GameMode that connects to the Function node for execution?

Hi Jason.
Thanks for the extensive reply.
Answering your questions:

  • I have a blueprint that contains that function, ToggleAll. Basically this blueprint is a container for all sorts of functions, like a library.
  • I don’t use onBeginPlay but rather drag the blueprint into the scene and call ToggleAll inside that function.
  • I call that function using Web remote, from a browser.
  • As I said this works in the editor but not during play. However I have added print commands and GetAllActorsOfClass works. Actually the “visible” check turns on and off, however the lights don’t do anything, it’s like it’s not refreshing or something.
  • The root component comes automatically when I plug the ForEach node to the ToggleVisibility node. I guess it makes no difference because, since the light is directly in the scene, root = the light. Maybe I can try to get the spotlight component manually.

thanks a lot for the feedback, I really appreciate it.

See if you can get the Spot Light component then.

I’m sorry, but I’m still missing something. When you say that it works in the Editor, what are you doing exactly to know that it works?
Are you using Simulation to test it or are you Playing in the Editor?

I guess what I mean is, when you say “Play” is that just hitting the Play button in the Editor or do you mean Playing as a Standalone Game/Launching.

Additionally, have you tried breaking the connection to the Web remote? Maybe just test it with an Event Begin Play for now and see if it works completely, that way you’ll have a better understanding of the issue.

Can you show your scene and the Blueprint that calls the function? It might be easier to determine the problem this way.

Lastly, you’ve re-built the Lighting, yes?

Thanks again, Jason.
Maybe better images than words, I made a little video with the problem.

I used the SpotLight component and it’s the same.
It’s working in the editor and I’m calling that function, which is inside a blueprint, via a browser with web remote.
And yes, with Play, I mean hitting the play button in the editor.
Haven’t tried yet the overall Begin Play, will do that next.

Did you ever edit the path of your Web Remote, as talked about here: Web Remote Control issues - Editor Scripting - Unreal Engine Forums

I was checking the Web Remote Doc (Remote Control Quick Start | Unreal Engine Documentation) and I didn’t see anything about it updating upon Play/during runtime; it seemed to be discussing updating values in the Editor only.

I assume the Prints still work because of where they’re being sent.

What I really don’t get is why the property actually updates when but it doesn’t do anything in the viewport.
I heard about the issue with paths changing but I don’t think I really need to change that because I’m not accessing the lights from Web Remote (in that case I should have a new path) but from inside the blueprint.
Actually if the path was wrong I wouldn’t be able to get the prints from the blueprint in play mode.
I’ll start a level from scratch. I started with a level from the marketplace so there might be some settings messing around. I’ll update soon.
Thank you Jason and everyone!

So, I tried just having the same code in the Level Blueprint, attached to BeginPlay…
… and it works.

I bound a key input to launch the code… it works.

I even did this (ToggleLights is just an Input Action on the letter “L”, and I actually call the function that I had in my blueprint)…
Sin título.jpg
…and it works!
So the problem is clearly with the way WebRemote is calling this function.

Jason, maybe you are right about webremote only working in editor mode, which goes against what I wanted to do… I will check that post again about changing the path.

I am immensely grateful for your feedback.


Jason, you were right about the paths.

When I changed my original path:

to the play equivalent (not sure what’s the best way to find this out apart from printing the path from the level blueprints):

…it started working.

My explanation is that when you call something with an editor path, you can only affect objects in the editor. It’s like when you are in play mode, the objects are in a different layer, so you have to call the blueprint that is in the play layer that will call the objects that are in the play layer… confusing I know.

In any case, thank you so much to Jason and Est_engine for the help.
Best community ever!