playcanvas / playcanvas/engine

User Data for Entities

Open
#6,049 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
16.8k
Forks
2k
Avg merge
4h 32m
Merged PRs (30d)
222

Description

It is often useful to differentiate entities from each other. For example scripting a behavior, based on the entity we touch (e.g. from physics). When working engine-only, its not much of an issue, as we can just modify the entity on instantiation, giving it extra properties needed. This feature is probably more beneficial for Editor projects.

At the moment, there are mainly two ways to differentiate entities under the same parent:

  • by tag
  • by name

Tags are pretty powerful, and allow filtering assets and entities, among other cookies. However, the tags are better suited for use during load times, rather than to be used during mid-life of the app:

// we have to first search the tag (e.g. we try to store a number in it)
if (entity.tags.has('intensity')) {
    // then convert string to number
    const str = entity.tags.list[0];
    const intensity = parseInt(str);
    // use intensity number
}

It would be much more efficient to allow to store a user defined number directly on the entity. Similar to how physics engines allow to store a user defined number for association, the entities could have a userData field for storing a plain number.

const intensity = entity.userData;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file, test, or entry point is named. Start by locating the entity implementation and the existing tag and name APIs, then determine where a userData value belongs in the entity lifecycle. Done means an entity can store and retrieve a user-defined number through entity.userData, with behavior covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
game-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.