Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom content ids and casting issues in Microservices #3854

Open
Leinnan opened this issue Jan 20, 2025 · 0 comments
Open

Custom content ids and casting issues in Microservices #3854

Leinnan opened this issue Jan 20, 2025 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@Leinnan
Copy link
Collaborator

Leinnan commented Jan 20, 2025

User is unable to cast to a custom item content.

Steps

  • create a Beamable Unity project
  • create a microservice
  • in common library code shared between create a new item class:
using Beamable.Common.Content;  
using Beamable.Common.Inventory;  
  
[ContentType("newTestContent")]  
public class NewTestContent : ItemContent  
{  
}  
  
[System.Serializable]  
public class NewTestContentLink : ContentLink<NewTestContent>  
{  
}  
  
[System.Serializable]  
public class NewTestContentRef : NewTestContentRef<NewTestContent>  
{  
    public NewTestContentRef(string id) : base(id)  
    {  
    }  
  
    public NewTestContentRef()  
    {  
    }  
}  
  
[System.Serializable]  
public class NewTestContentRef<TContent> : ContentRef<TContent> where TContent : NewTestContent, new()  
{  
    public NewTestContentRef(string id) : base(id)  
    {  
    }  
  
    public NewTestContentRef()  
    {  
    }  
}
  • Create a new content of NewTestContent type in Content Manager and publish it: items.newTestContent.myTestContent
  • Add this method to the microservice:
[ClientCallable]  
public async Task Test1()  
{  
    try  
    {  
        InventoryUpdateBuilder iub = new InventoryUpdateBuilder();  
        iub.AddItem("items.newTestContent.myTestContent", new Dictionary<string, string>());  
  
        await Services.Inventory.Update(iub);  
        var items = await Services.Inventory.GetItems( new ItemRef("items.newTestContent.myTestContent"));  
        for(int i = 0; i < items.Count; i++)  
        {  
            ItemContent itemContent = items[i].ItemContent;  
            BeamableLogger.Log($"Type: {itemContent.ContentType}, Id: {itemContent.Id}, Name: {itemContent.ContentName}");  
            NewTestContent concreteItem = itemContent as NewTestContent; // As resolves to null instead of NewTestContent  
            if(concreteItem == null)  
            {  
                BeamableLogger.LogError("The item is null");  
            }  
        }  
    }  
    catch (Exception e)  
    {  
        BeamableLogger.LogException(e);  
    }  
}
  • Call the microservice endpoint from newly created BeamContext in the Unity.

Expected result

  • Microservice outputs something like: Type: items.newTestContent, Id: items.newTestContent.myTestContent, Name: myTestContent
  • concreteItem is not null

Current result

  • Microservice outputs: Type: items, Id: items.myTestContent, Name: myTestContent
  • concreteItem is null

Metadata

  • SDK version: 2.0.2 of engine integration, 3.0.2 for Microservices and CLI
  • Engine version: Unity 2022 LTS
  • Operating System: Windows
@Leinnan Leinnan added the bug Something isn't working label Jan 20, 2025
@cdhanna cdhanna added this to the CLI 3.2.0 milestone Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants