#SpriteRenderer issue related to network spawning

1 messages · Page 1 of 1 (latest)

dusk quartz
#

Hello! In my current Unity project, I'm encountering an issue with the SpriteRenderer not displaying a selected sprite despite being in a valid configuration. There are a number of moving parts to this issue, but I've chosen this forum as it ultimately results in a rendering failure and I cannot discern a precise cause.

Disclaimer: I'm a Unity newbie. This is my first Unity project and I appreciate I am probably rather lacking in detailed knowledge on these components and how they interact with Unity's internals. I have made a best effort to research this issue online, troubleshoot it myself, and ask for help in spaces dedicated to the multiplayer library potentially involved (details below), but I apologise in advance if I use nonstandard terminology or need extra explanation. Please feel free to ask me for any information that may be of benefit for making useful suggestions.

The problem. The game is intended to be an MMORPG, and I have a configurable EntitySpawner which periodically instantiates Entity instances from an assigned prefab. The first time this "spawn" triggers, it usually (but not always!) does not exhibit any issues (if triggered in Update; see symptoms below.) However, upon the enemy being despawned or killed, and then respawned by the spawner, the new instance is usually (but not always!) not visible. This is despite all properties of the new instance being correct to the extent that I can verify, with all other functionality of the instance working correctly, and the SpriteRenderer sprite being correctly set, not occluded by other sprites, etc.

Networking. Being an MMORPG, there is a networking aspect to this: I am relying on the PurrNet package to implement my networking. Spawning the player character is done locally by the owning player and validated on the server, which works as intended; however, in this instance the new Entity instance is being spawned by the server. I cannot confirm whether or not this is a contributing factor but I would be remiss to not mention it. I have already spoken to their support channel about this issue, and exhausted all available suggestions.

Detailed symptoms list. Please find below a list of point-form details that may be of importance:

  • No errors, logs or warnings appear which would be indicative of obvious bugs
  • When the spawn function of EntitySpawner is triggered from LateUpdate or FixedUpdate instead of Update, the first Entity instance spawned has never rendered as intended, instead always experiencing the same issue described.
  • The sprite of the prefab is never modified by any script, and is already set in the prefab at compile time
  • The Entity instance has an attached HP bar; this is not part of the prefab, and is spawned by a script in the instance upon spawning. This HP bar always presents correctly, even if the main sprite does not render.

Troubleshooting steps tried. Please find below a list of attempted troubleshooting steps:

  • Disabling and re-enabling the SpriteRenderer
  • Removing and re-adding the SpriteRenderer component
  • Changing the sprite to be rendered
  • Reordering components
  • Modifying the Z coordinate of the associated Transform to ensure it is not occluded or behind the camera
  • Changing the sort ordering of the SpriteRenderer
  • Moving the instance to a position with no other sprites to ensure it is not occluded
  • Disabling the NavMeshAgent of the Entity instance
  • Disabling the NetworkTransform of the Entity instance (a PurrNet module for plug-and-play position synchronization between clients)

Media. Following this main post in the thread will be some media of the game, displaying the issue I am encountering.

Any suggestions or pointers are appreciated! I simply don't know what else I can try at this juncture, and am hoping someone with more experience might be able to offer some pointers.

#

A screenshot of the inspector panel of the above Entity instance experiencing the issue. The sprite field is set with a valid sprite. Other components collapsed to fit on my screen, can expand and share if needed

#

A screenshot of the main Camera in use. The Z coordinate never changes by design. The X and Y coordinates change to follow the associated player character.

jaunty holly
#

How are you despawning/killing it?

dusk quartz
# jaunty holly How are you despawning/killing it?

Spawning is done via this function in EntitySpawner, which executes on the server/host only:

public void DoSpawn()
    {
        _attachedInstance = Instantiate(spawnPrefab, transform.position, transform.rotation);
        _attachedInstance.transform.SetParent(transform);
        _attachedInstance.RemoveOwnership(true);
        _attachedInstance.died += OnAttachedEntityDied;
    }

DoSpawn() is called from Update() when the correct conditions are met.

I have alternated between using Destroy(entity), entity.Despawn(), or both. None of these methods have had any impact on how the issue behaves.

coarse briar
#

This very unlikely to be a rendering issue.
The first thing I'd try on the client with the issue, is pause the game, switch to scene view 3d mode, focus on the entity object, rotate around it and confirm that the sprite doesn't get rendered at all.
If it doesn't, then start looking at the components. To render something, you need a renderer and a material. Check these two for any differences with the working version.

coarse briar
jaunty holly
#

what are u using to spawn it out of curiosity

#

im wondering if there is some sort of syncing issue

dusk quartz
# coarse briar Compare the transform as well. Rotation of -90 on x definitely doesn't sound rig...

You were absolutely right with this, I hadn't realized this was being set occasionally. It seems the NavMeshAgent rotates the agent if some properties aren't set correctly, and I was setting these properties in OnSpawned() (A PurrNet function similar to Start()) which it seems is often fired too late to come before the first Update() call. Since modifying these properties to be set from Start(), the issue no longer presents.

Very impressed that you caught this so quickly! I apologise that my own assumptions on the cause of the issue were inaccurate.

dusk quartz
jaunty holly
dusk quartz
#

PurrNet hooks into calls to Instantiate if the prefab given has a NetworkIdentity component, which PurrNet uses to track instances across the network. It manages the spawning of the instance across clients autonomously

jaunty holly
#

With a lot of libraries you usually have to spawn on the network side through their API

#

ahh

dusk quartz
#

I'll mark this as solved seen as the issue no longer presents, thank you again for the assistance, I can't believe I didn't notice this sooner