Page MenuHomeFeedback Tracker

ItemPreviewWidget Item should be of Type Object and not EntityAI
New, UrgentPublic

Description

The ItemPreviewWidget currently only accepts an EntityAI when setting it as the preview Item, but there are many cases, where you want to show something like a House or similar as a preview, but you cannot simply do that.
The only way this is currently possible, which is more like a workaround is to just put an Object in there and ignore the Unsafe Down-Casting warning.
It will still work as expected, but you get a warning, that the Object cannot be safely downcasted.

I would suggest changing the whole SetItem and GetItem to an Object Item or add another ItemPreviewObjectWidget if they are not compatible with the View and Flip Cargo options you have with the normal ItemPreviewWidget

Details

Severity
Minor
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General
Steps To Reproduce

Use something like this to set the Item as a Preview:

	void SetItemPreview() {
		string itemName;
		if (!GetCurrentClassname(itemName))
			return;
		Object newItem = GetGame().CreateObject(itemName, vector.Zero, true);
		item_preview.SetItem(newItem);
		item_preview.SetModelOrientation("-45 180 0");
		if (previewedItem != null)
			GetGame().ObjectDelete(previewedItem);
		previewedItem = newItem;
	}

You will get the Error message: Unsafe down-casting, use 'EntityAI.Cast' for safe down-casting

Event Timeline

LBmaster created this task.Dec 12 2022, 8:59 AM