#Canvas problem
15 messages · Page 1 of 1 (latest)
As far as i know, i cant put navmesh into the childs, character is not moving and not syncing
That's inside of my prefab and Ship parent components. ShipMain is my ship asset
I have two ideas:
-
I am not 100% certain about whether or not this would work, but you could maybe have a
LateUpdate()in a script on the parent "Ship" game object that sets the canvas rotation to zero on every frame. Like I said though, idk if that will work for you or not. -
Make a new prefab. Maybe call it "ShipUiCanvas" or something like that.
- You make your "ShipUiCanvas" prefab, and only have it contain the "Canvas" game object and it's children (move out of "Ship" prefab and into "SkipUiCanvas" prefab)
- Have a script on your ship spawn your "ShipUiCanvas" game object and save a reference to it. Use that reference to the instantiated canvas prefab for your ship's script(s) to interact with the canvas.
- Also have your "Ship" script update the position of the "Canvas" instance on every frame so that the position of the canvas instance is always relative to the position of the ship.
- Obviously you only spawn the canvas game object if
isLocalPlayer == true.
There might be better ways, but those two are the first that came to mind.
you mean i will instantiate canvas as New gameobject right?
Yep. Have the canvas only exist if you are host or client. There are many ways to do it, but somehow have the canvas reference the networked game object that it is supposed to display information for, and then use a script to run non-networked logic to set the canvas position in the world to be the position of the networked game object + some offset (on every LateUpdate).
The server shouldn't have to deal with canvas/UI stuff anyways so if you do it this way you get better efficiency as it's the client that does the work of managing and updating the canvas.
or i can spawn this with NetworkServer.Spawn() and i can sync to all clients
Sure you could spawn it, but I still do not recommend it. It's better to let the clients spawn it so your server isn't processing all of that stuff. Waste of CPU cycles on the server.
I've done what you did in your screenshot of LateUpdate() before and never saw any meaningful loss of performance.
Like I said, you're better off spawning the canvas (or just the UI elements in general) on the client. The canvas object can be updated using whatever data is populated in the networked player game object.
okay
thank you so much for help, I was brooding about this 😄
@gusty warren So what kind of system would you recommend for NPC canvases?
Same system.
Make a prefab for a canvas that is intended to be used for an NPC.
Add a property to your NPC so you can configure the canvas prefab to be used for the NPC.
On the client, instantiate a new instance of the canvas prefab, and keep the canvas details and position updated in whatever manner you see fit.
Remember: Even if the canvas needs to be seen by all players, it'll be ok because you can have every client spawn the canvas on their end. Everyone will still see the same things because everyone is running the same code and receiving the same updates for the networked NPC that is keeping the canvas updated.