is It possible to expose abstract classes and interfaces to lua and call virtual functions with the actual reflection system?

was trying to export to lua get and set material from static mesh and then to expose the IMaterial interface to lua for realtime material property changes.

I used AZ_RTTI(IMaterial, “{42AB3609-EEA6-4464-B566-0B619EA03792}”); in IMaterial Struct

AZ_RTTI(CMatInfo, "{43A301D9-E3CA-4A89-A008-8C52A3C333ED}",IMaterial);
in cMathInfo the class that implements IMaterial interface.

and then in StaticMeshComponent added it’s class to behaviour context but it compiles but doesn’t show up in the editor.

		if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<IMaterial>("Material")
->Method("SetGetMaterialParamFloat", &IMaterial::SetGetMaterialParamFloat)
->Method("GetSubMtlCount", &IMaterial::GetSubMtlCount)
->Method("GetName", &IMaterial::GetName)
->Method("GetSubMtl", &IMaterial::GetSubMtl)
//->Method("SetGetMaterialParamVec3", &IMaterial::SetGetMaterialParamVec3)
;
behaviorContext->EBus<MeshComponentRequestBus>("MeshComponentRequestBus")
->Event("GetWorldBounds", &MeshComponentRequestBus::Events::GetWorldBounds)
->Event("GetLocalBounds", &MeshComponentRequestBus::Events::GetLocalBounds)
->Event("SetVisibility", &MeshComponentRequestBus::Events::SetVisibility)
->Event("GetVisibility", &MeshComponentRequestBus::Events::GetVisibility)
->VirtualProperty("Visibility", "GetVisibility", "SetVisibility");
behaviorContext->EBus<MaterialRequestBus>("MaterialRequestBus")
->Event("SetMaterial", &MaterialRequestBus::Events::SetMaterial)
->Event("GetMaterial", &MaterialRequestBus::Events::GetMaterial);
//->VirtualProperty("Material", "GetMaterial", "SetMaterial");
auto statMeshCtx =
behaviorContext->Class<StaticMeshComponent>();
statMeshCtx->RequestBus("MeshComponentRequestBus");
statMeshCtx->RequestBus("MaterialRequestBus");
//also tryed concatenated.
}

Can someone point out what is wrong whit this implementation based solely on guessing as documentation about reflection is very lacking on this subject and I haven’t found any comparable example in the source.

Updated tried to move reflection of IMaterial in IMaterial.h

		static void Reflect(AZ::ReflectContext* context){
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<IMaterial>("Material")
->Method("SetGetMaterialParamFloat", &IMaterial::SetGetMaterialParamFloat)
->Method("GetSubMtlCount", &IMaterial::GetSubMtlCount)
->Method("GetName", &IMaterial::GetName)
->Method("GetSubMtl", &IMaterial::GetSubMtl)
//->Method("SetGetMaterialParamVec3", &IMaterial::SetGetMaterialParamVec3)
;
}
}

then call it from static mesh with the context with no luck maybe it is not how these things work.

as a sidenote I had to disable SetGetMaterialParamVec3 as Vec3 is just another kind of vector3 that isn’t mapped to lua, I guessed that actually you need a wrapper to do these kind of things.My last chance is to wrap every function in a system component using ebus and also wrap the pointer to IMaterial but I just want to learn the best pratice and apply just that.

Hey @Gamely, I’ve created an inquiry ticket to see if we can get someone to get you some answers on this.

I did a simple test and it worked with

AZ_TYPE_INFO

it required a recompile.

I’ll try to understand whay it didn’t worked the first time.

Awesome work. Keep me informed as to what you find and I’ll update the ticket.