Interaction
Converting instances to actors
To convert a mesh instance into an actor, call EiiWorldSubsystem::ConvertInstanceToActor
or EiiWorldSubsystem::ConvertHitInstanceToActor
. The second function is easier to use when you have a trace hit result.
It's up to the game logic to decide which instances to convert and when. In our examples, we perform a sphere trace to find an object to interact with when the player presses a mouse button. As an example, a racing game might want to find instances in front of the car to convert them to actors ahead of a potential collision.
Converting actors to instances
If the player didn't interact with the converted actor, it's best to convert that actor back to an instance. This can be done with EiiWorldSubsystem::RestoreActorToInstance
or EiiWorldSubsystem::RestoreHitActorToInstance
.
If the conversion back to a mesh instance succeeds, the game should destroy the actor to prevent both an actor and a mesh instance from existing in the same location.
Issues related to World Partition
When an instanced mesh is loaded by World Partition, it contains all of its original instances, even if some of those instances were interacted with and shouldn't be present. Because of that, it may render outdated instances for a single frame (see video below).
The way we handle this problem in our example HISM/ISM classes UEiiHierarchicalInstancedStaticMeshComponent
/UEiiInstancedStaticMeshComponent
is by initially hiding the mesh for one frame as soon as it begins play or is registered. EiiWorldSubsystem
then removes the instances that were interacted with previously and the mesh renders properly in the next frame.
You may want to perform a similar logic in your HISM/ISM Blueprint or use the example classes we provide.
Saving and loading the game
When implementing a save/load system for the game, ensure that all actors created from converted mesh instances are properly saved, as they won't be automatically restored otherwise. Additionally, the EiiDataActor
, which the plugin automatically spawns to track instance conversions, must also be included in the save.