#Unity with Steam, Avatar Issue

1 messages · Page 1 of 1 (latest)

cursive creek
#

Hello guys, i was following a tutorial about steam and unity. Everything is ok except the steam avatar. The avatar is not loading to the rawImage. I tried to print out the ImageID value and it prints as 0.

public class PlayerListItemScript : MonoBehaviour
{
    public string PlayerName;
    public int ConnectionId;
    public ulong PlayerSteamId;
    private bool avatarRecieved;

    public TMP_Text playerNameText;
    public RawImage playerAvatar;

    protected Callback<AvatarImageLoaded_t> AvatarImageLoaded;

    private void Start()
    {
        AvatarImageLoaded = Callback<AvatarImageLoaded_t>.Create(OnImageLoaded);
    }

   

    private void GetPlayerIcon()
    {
        int ImageID = SteamFriends.GetLargeFriendAvatar((CSteamID)PlayerSteamId);
        print(ImageID);
        if (ImageID == -1)
        {
            return;
        }
    }

    public void SetPlayerValues()
    {
        playerNameText.text = PlayerName;
        if (!avatarRecieved)
        {
            GetPlayerIcon();
        }

    }
    private void OnImageLoaded(AvatarImageLoaded_t callback)
    {
        if (callback.m_steamID.m_SteamID == PlayerSteamId)
        {
            playerAvatar.texture = GetSteamImageAsTexture(callback.m_iImage);
        }
    }

    private Texture2D GetSteamImageAsTexture(int iImage)
    {
        Texture2D texture = null;

        bool isValid = SteamUtils.GetImageSize(iImage, out uint width, out uint height);
        if (isValid)
        {
            byte[] image = new byte[width * height * 4];

            isValid = SteamUtils.GetImageRGBA(iImage, image, (int)(width * height * 4));

            if (isValid)
            {
                texture = new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false, true);
                texture.LoadRawTextureData(image);
                texture.Apply();
            }
        }
        avatarRecieved = true;
        return texture;
    }


}

celest lily
cursive creek
#

I am the only on that's in the lobby, and yes i have a steam avatar. I don't know why this occurs.

celest lily
#

Might be obvious, but are you sure you're passing the steam id correctly?

cursive creek
# celest lily Might be obvious, but are you sure you're passing the steam id correctly?

Sorry for the late response but it seems that you are right. Both of the imageID and the SteamID is 0. I checked the script that i get SteamID,
Here it is:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
using Steamworks;
using UnityEngine.SceneManagement;

public class CustomNetworkManager : NetworkManager
{
    [SerializeField] private PlayerObjectControllerScript GamePlayerPrefab;
    public List<PlayerObjectControllerScript> GamePlayers { get; } = new List<PlayerObjectControllerScript>();

    public override void OnServerAddPlayer(NetworkConnection conn)
    {
        if (SceneManager.GetActiveScene().name == "Lobby")
        {
            PlayerObjectControllerScript gamePlayerInstance = Instantiate(GamePlayerPrefab);
            gamePlayerInstance.ConnectionID = conn.connectionId;
            gamePlayerInstance.PlayerIDNumber = GamePlayers.Count + 1;
            gamePlayerInstance.PlayerSteamID = (ulong)SteamMatchmaking.GetLobbyMemberByIndex((CSteamID)SteamLobby.Instance.CurrentLobbyID, GamePlayers.Count);
print(SteamMatchmaking.GetLobbyMemberByIndex((CSteamID)SteamLobby.Instance.CurrentLobbyID, GamePlayers.Count));
            NetworkServer.AddPlayerForConnection(conn, gamePlayerInstance.gameObject);

        }
    }
}

I printed out and it is zero. What is the issue

celest lily
#

if you want something more specific you'll have to show more of the code

cursive creek
#

Let me take screenshots. I use callbacks of the steam but idk what is the issue.
These are the script that i use to get steam id or anything like that. I think the main issue is CustomNetworkManager

celest lily
#

You're joining the lobby via the steam overlay?

#

this is probably the issue.
You can't call GetLobbyMemberByIndex before GetNumLobbyMembers

#

you said you're following a tutorial, but I'd double check with the actual steamworks api wiki because this kind of stuff is clearly written there

#

Also, in arrays Count is probably out of bounds. Indexes are 0 -> Count - 1 (included)

cursive creek
#

Bro i just figured it out. The issue was that i didn't set the CurrentLobbyID in SteamLobby script after i created the Lobby. I just wrote CurrentLobbyID = callback.m_ulSteamIDLobby; then it worked, very very gratefull for te help, thanks!