Issue when reload and activate GameObject

Hi :), hpoing you’re doing well.
I have a proyect with a VideoPlayer. When that VideoPlayer ends (using the ended for HTMLMediaElement), I invoke some Events and other stuffs, and also I call a method for activate an object using setActive(gameObject, ture). I know that the code reachs that method which calls setActive(gameObject, ture) but when I reload the page and the video triggers the ended event, that method is called again but it doesn activate the object again. Ive tried instead of activate, using instantiate and instance the object instead of activate it but the same thing happens : the first time, when I load the page, it does instantiate the object, but when I reload it doesn’t do it anymore. I’m in a networking room but I don’t know if that has something to do, because the rest of the app works fine. Do you know what`s happening ?
Thanks in advance : )

Original Post on Discord

by user 632418299711324161

Hello there – I’m an AI powered assistant :robot: that might be able to help you with your question. Would you like me to try helping you?

How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.

Help requested: please wait a moment…

Here is what I found for you :brain: Discord

Hello DiegoEloko, I’m here to help! Your issue might be related to networked object instantiation and state synchronization in a multiplayer setting. When you’re in a networking room and instantiate or activate objects, you need to ensure these actions are properly synced across the network, otherwise they might not persist after a page reload.

The SyncedTransform component could be relevant if the object you’re trying to activate or instantiate should have its state synchronized across the network. Also, consider the object’s lifecycle and whether it’s being properly re-initialized on new connections or page reloads. If network ownership or permissions are involved, you also need to check if the correct client has the authority to make changes to the object’s state.

Here are some general troubleshooting steps:

  1. Ensure that your VideoPlayer’s ended event callback is properly bound each time the page loads.
  2. Check the networked object’s synchronization state and ownership.
  3. If you’re using SyncedRoom or SyncedTransform, confirm they’re configured correctly and working as expected on page reloads.

Inspecting the VideoPlayer and relevant network components, such as SyncedRoom, or SyncedTransform during the page reload might reveal more details. It’s also worth reviewing any console logs or network traffic for errors or missed synchronization messages.

Without the explicit code, it’s hard to pinpoint the issue, but these steps should help you in diagnosing the problem (see the documentation).

1 messages left GPT 4
Thanks for your feedback!

That doesn’t worked. I just want that object activated in local, I don’t care synchronized it. I’m sure that the reference of the object which i want to activate is not undefined or null. I’ve also have tried use the next lines of code :

const game = as Object3D; 
        game.visible = true; 
        game.userData.interactable = true;```
But doesn't work. the problem persist when I reload the page. the video ends and when the object should be activated/instantiated , it doesn't.

*by user 632418299711324161*

If you don’t want to synchronize the object and want it to be activated locally, you can directly set its visibility to true. However, if that’s not working, you may need to check if the component causing the issue is initialized properly. Additionally, ensure that the asset is being loaded correctly and that there are no issues with object instantiation. You can also try activating the object on the “start” lifecycle method to ensure it is activated when the component is loaded. If all these have been verified and the issue still remains, there might be something in the code or the environment causing the problem. Further debugging or checking for error messages might help identify the root cause of the issue.

0 messages left GPT 3.5
Thanks for your feedback!

If the object/ your video is already active and you call setActive again then nothing will happen to the videoplayer (because the active state hasnt changed). Why do you not set the video to loop or just call play again on the video player directly?

The video doesn’t have problems. When I reload the page and after an interaction (a button) , the video plays. Also, there are some events when the video ends and those events are invoked. The problem is the event that setActive the targetObject happens (because I’ve logged a line) but it doesn’t activate it. This happens when I reload the page, the first time it works fine.
Maybe I could try setActive(targetObject,false) in a OnDisable ?

by user 632418299711324161