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

Accessing the entities from outside/modifying the fragment values #28

Open
RFornalik opened this issue May 3, 2022 · 2 comments
Open
Labels
Documentation Improvements or additions to documentation

Comments

@RFornalik
Copy link

The documentation/sample project would get much more beneficial if there was a section for accessing entities/their fragments from outside the system. For example: Setting destination point for certain entities that move torwards points.

@Megafunk Megafunk added the Documentation Improvements or additions to documentation label May 4, 2022
@Megafunk
Copy link
Owner

Megafunk commented May 4, 2022

If by "outside the system" do you mean not the entity being processed on? So far, It looks like entity fragment data can be accessed in two different way outside the processing execution context:

  • Accessing fragment data with an FMassEntityHandle called Entity: through the subsystem directly:
	EntitySystem = World->GetSubsystem<UMassEntitySubsystem>();

	//Get a reference
	EntitySystem->GetFragmentDataChecked<FSampleColorFragment>(Entity).Color = FColor::Blue;

	//Get a pointer
	EntitySystem->GetFragmentDataPtr<FSampleColorFragment>(Entity)->Color = FColor::Blue;


	//FStructView is kind of like a pointer to an instanced struct
	FStructView StructView = EntitySystem->GetFragmentDataStruct(Entity, FSampleColorFragment::StaticStruct());

	StructView.GetMutable<FSampleColorFragment>().Color = FColor::Blue;
  • Accessing fragment data with a new FMassEntityView. This is a struct that stores the archetype data too so it has some nice extra functionality:
	EntitySystem = World->GetSubsystem<UMassEntitySubsystem>();

	FMassEntityView EntityView(*EntitySystem,Entity);

	EntityView.GetFragmentDataPtr<FSampleColorFragment>(Entity)->Color = FColor::Blue;

        //The Entityview can also get the entity's shared fragments and even check for tag presence:
	EntityView.GetSharedFragmentData<FSharedNiagaraSystemFragment>().ParticlePositions = Whatever;

	if(EntityView.HasTag<FSampleMoverTag>()) 
               DoStuff();

It's also probably slightly faster to do the whole FMassEntityView thing if you need to change more than a single fragment on the entity as it caches the archetype data, saving some extra work. (I think)

I'll document this stuff soon! I'm still learning stuff on the go as I use the API more.

@vorixo
Copy link
Collaborator

vorixo commented May 5, 2022

Next consideration: How to get a FMassEntityHandle or a FMassEntityView from actor code.

  • Get Nearest entity of type
  • Query an entity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants