cancel
Showing results for 
Search instead for 
Did you mean: 

Can we use setTexture in local mode

FreakyChest
Member

Trying to create gun with some texture switching, needs to run in local.

I have a script that has no issue switching between images when it is global script, when I switch to local script and change owner to player, it no longer works and throws, Exception encountered running bridge method 'SetMeshTexture': Failed to set mesh texture. Is there a way to use setTexture in local mode, or do we have to use a server script and then have local script send to server script?

Tested further: Made script that when I pick up, it set owner to player and switches through textures and when put down it switchers server to owner. Test server works, client doesn't, no matter how many times I go back and forth. setTexture requires textureAsset, so doesn't seem related to using the UI loading using ImageSource.fromTextureAsset(asset).

There is anoptions — Indicates the players to apply the texture for. Which is confusing, does that mean all instances of the mesh will look one way to some players and another way for others?

1 ACCEPTED SOLUTION

Accepted Solutions

FreakyChest
Member

Short answer is that since "local scripts cannot access or use texture assets", then MeshEntity.setTexture should not be used and  shouldn't work locally. "If you want to set a new UI-optimized texture for an entity, you must send an event to a default script and let it trigger the API call" (getting started with local scripting).

MeshEntity.setTexture can work locally when you set options to the local player (but likely shouldn't work), but seems to have stability issues.

meshEntity.setTexture(texture,{players:[this.entity.owner.get()]});
 
I tested this with no options and empty array which both failed when ran locally (player owned).
When I used the code above it works, but desktop editor has crashed more then once, takes a little bit of time (a min), volume goes out and freezes. 

View solution in original post

4 REPLIES 4

SeeingBlue
Mentor

Don't confused the UI ImageSource with the meshEntity styling. They are different. While the UI can update ImageSource on a per player basis, meshEntity cannot. I honestly was not aware that local scripts could not swap textures, but it looks like you've proved it here.

Upcoming Events:
Performance Pro - UI Unleashed - Building Responsive & Performant Interfaces Thursday June 19th 5:00 PM PT - Register
June Programming Calendar

I wasn't confused, another creator mentioned it (in discord) and I made sure to write why it wasn't possible. To me there was still a small chance that there was overlap, even if one is UI specific and one meshEntity specific I did still test to make sure it was still not possible, tested by just getting the image to trigger the image to load just in case (didn't work, not a big deal)....

I think the only other thing I can test is, can assets be spawned locally (player owned), if not then we maybe we can't access assets while local and its not just texture assets? If that is the case then that would mean .setTexture just can't be used locally and would need to use UI or entity switching or future update.... Going to test that now, access asset while player owned.

FreakyChest
Member

Short answer is that since "local scripts cannot access or use texture assets", then MeshEntity.setTexture should not be used and  shouldn't work locally. "If you want to set a new UI-optimized texture for an entity, you must send an event to a default script and let it trigger the API call" (getting started with local scripting).

MeshEntity.setTexture can work locally when you set options to the local player (but likely shouldn't work), but seems to have stability issues.

meshEntity.setTexture(texture,{players:[this.entity.owner.get()]});
 
I tested this with no options and empty array which both failed when ran locally (player owned).
When I used the code above it works, but desktop editor has crashed more then once, takes a little bit of time (a min), volume goes out and freezes. 

ya, regular assets cannot be spawned by local scripts either.

Upcoming Events:
Performance Pro - UI Unleashed - Building Responsive & Performant Interfaces Thursday June 19th 5:00 PM PT - Register
June Programming Calendar