Spawning Dynamic Slice returns all ok, but nothing to see

Hello,

I’am lost at the moment. I’ll try to spawn a dynamic slice from C++ code. Slice path is “Slices/Test.dynamicslice”, so this should be ok. But nothing is to see. Isearchd the forum already and made sure that I use functions like here: Can you guys tell me how to Spawn dynamic Slices from C++?

AzFramework::SliceInstantiationTicket lTicket;

	AZ::Data::AssetId lSliceAssetId;
	AZ::Data::AssetCatalogRequestBus::BroadcastResult(lSliceAssetId,&AZ::Data::AssetCatalogRequests::GetAssetIdByPath,pSliceName, AZ::AzTypeInfo<AZ::DynamicPrefabAsset>::Uuid(), true);
	if (lSliceAssetId.IsValid()) {
		AZ::Data::Asset<AZ::DynamicSliceAsset> lSliceAsset;
		lSliceAsset.Create(lSliceAssetId, true);
		if (lSliceAsset.GetId().IsValid()) {
			AzFramework::GameEntityContextRequestBus::BroadcastResult(lTicket, &AzFramework::GameEntityContextRequests::InstantiateDynamicSlice, lSliceAsset, pWorld, nullptr);
			//LmbrCentral::SpawnerComponentRequestBus::Event(GetEntityId(), &LmbrCentral::SpawnerComponentRequestBus::Events::SpawnSliceAbsolute, lSliceAsset, pWorld);
			
			AzFramework::SliceInstantiationResultBus::MultiHandler::BusConnect(lTicket);
		}
	}
	
	AZ_Error("PlayerActorComponent", lTicket, "Spawning slice failed trying to spawn %s", pSliceName);

	mTicket = lTicket;

	return lTicket;

Hi @masm32,

Your code looks correct. I’ve used it myself to instantiate the dynamic slice. I’ve hardcoded some of the variables in your code for ease of testing. Here is what I used

AzFramework::SliceInstantiationTicket lTicket;
AZ::Data::AssetId lSliceAssetId;
AZ::Data::AssetCatalogRequestBus::BroadcastResult(lSliceAssetId, 
    &AZ::Data::AssetCatalogRequests::GetAssetIdByPath,"slices/simple.dynamicslice", 
AZ::AzTypeInfo<AZ::DynamicPrefabAsset>::Uuid(), true);
if (lSliceAssetId.IsValid()) {
    AZ::Data::Asset<AZ::DynamicSliceAsset> lSliceAsset;
    lSliceAsset.Create(lSliceAssetId, true);
    if (lSliceAsset.GetId().IsValid()) {
        AzFramework::GameEntityContextRequestBus::BroadcastResult(lTicket, &AzFramework::GameEntityContextRequests::InstantiateDynamicSlice, lSliceAsset, AZ::Transform::CreateTranslation(AZ::Vector3(0, 0, 0)), nullptr);
    }
}

Here are the steps I followed to successfully spawn a dynamic slice:

  1. I created a simple slice with one entity and a ‘Shape’ component. I selected a ‘capsule’ shape for the shape component(you can select any shape). I enabled ‘Game View’ for the capsule shape. I saved the slice as ‘simple.slice’. I set the slice as a dynamic slice.
  2. I Created an entity in the editor and gave it a component(for this example, I used MeshComponent but you can use any component for this). I made sure this entity was at (0,0,0) so that I know where I’m looking at.
  3. In the Activate() method of the MeshComponent, I added the above code. I did this because starting the game would activate all entities in the scene and thus activating the MeshComponent of my entity.
  4. I entered the game mode by hitting ctrl+g and I was able to see the capsule

If you are unable to see your dynamic slice instantiated when the game starts, make sure that you have followed the below steps:

  • Make sure the above code is triggered when the game begins. I put this code in the Activate() method of the MeshComponent because I knew it would be activated when I enter the game mode. You can put debug breakpoints in the above code to see whether it’s being hit when you hit ctrl+g
  • Make sure that your dynamic slice would be visible in the game mode. Notice that I enabled ‘Game View’ for the capsule shape. Not all components would be visible in the game mode by default. Sometimes you would have to enable certain properties to do that. You can quickly instantiate your lsliceAsset slice in the editor and enter the game mode to see whether it would be visible or not.
  • Make sure your dynamic slice is instantiated at a location that’s within the field of view of the camera in the game mode. I put everything at (0,0,0) to test this easily. So, make sure pWorld is within the field of view of the camera in the game mode.

Let us know if this fixed your issue and if you have any other questions.

2 Likes

Hello Ram_Kappagantula,

I will try it if I solve the other problem with the ReplicaChunk.
I will tell you if the slice problem is fixed or not.

Joerg

Hi @masm32, let us know if this has been resolved or if you still need help.

Thanks!

1 Like

Hello @lmbr_Saulty,

I have to say sorry, but I am not using Lumberyard anymore. I am back to Unreal Engine. Working over one month with Lumberyard, with slow progress. After five days back in Unreal I got playable Multiplayer with Replication working. But the biggest drawback for me isthe license restrictions to host games only on amazon servers.
Maybe if some of the other issues like terrain size and fbx importer are fixed and the documentation is mature, I will take another look.

Hi @masm32, thanks for letting me know. Best wishes to your project and please keep an eye out for new Lumberyard updates from time to time as we continue to make improvements.

Best.

1 Like