#archived-code-general
1 messages Β· Page 410 of 1
I mean I guess, but they said "platformer" not "platform fighter". Anyway why don't we just let the person clarify instead of making assumptions and potentially giving useless advice
google says
- fighting
- sandbox fighting
- crossover platform fighting
- action
- platformer
- action fighter
- platform fighter
- platform battler
- arena fighter
- party fighter
sandbox
someone on reddit said smash is a smashlike...
that honestly makes sense
it is genre defining
that seems like the best description
same for roguelike and soulslike
its a first
weird that castlevania 1-4 aren't metroidvanias though
is it not
not enough metroid in it
If I have splines running up a 2d silhouette of a tree, can I rig and animate the tree to sway and adjusted the splines to conform to the animated movements?
Objects animating up the tree spline would still stay on track as it sways. If that's not possible what alternative could I consider?
Iβm guessing youβd have to animate the spline knots as well, since they arenβt (AFAIK) attachable to other things
Correct. I've done this -- it can have some interesting performance impacts...
notably, calculating the up-vector is quite expensive, so the spline caches a bunch of them and interpolates between them when query for that
but if you're moving the spline knots every frame, it has to rebuild that cache every frame
I also ran into additional editor-only caching of...some kind. i should probably figure out exactly what I've deleted from the Splines scripts...
https://paste.myst.rs/ux0jv8o4
here's how I did the actual parenting
Probably a lil bit of a stupid question, but how would achieve a 1:1 rotation of IK chain tip and target?
i.e. my hand (tip) rotates with the target but they don't have the same transform values because my hand is a parent of the forearm. How would I even change my hand rotation to world space?
Wait, can I set rotation weight to 0 and then rotate my actual hand? Would that be it?
its a beat-em-up 
you beat the opponents up
https://discussions.unity.com/t/how-to-properly-load-a-sprite-from-an-atlas/860650/5 does anyone have any suggestions? I wanna use a sprite atlas for my many UI icons in an image component iconAtlas.GetSprite("icon_" + itemName); but it aint batching
so how do I prevent clones?
note that the "cloning" doesn't mean it's copying the entire texture
you're getting an object that points to a texture and tells you where on it to look
Hey! I'm scratching my head about this problem that I think stems from weird usage of cinemachine + Animation Rigging.
I was hoping someone could confirm/deny my assumptions, and if possible give me a jumping point for a better alternative?
Context: I have an FPS controller with an animated full-body model. There's a cinemachine camera in the hierarchy of the controller that follows a transform in the animated skeleton's eyes.
I use animation rigging to parent-constrain the player's weapon by the camera (to keep the weapon center frame). Additionally, I use animation rigging to rotate the player's head/body towards where the camera is aiming (via an aim constraint pointed at a child transform of the camera).
Together, this leads to a pretty delightful behavior that follows this chain:
- I rotate the transform on the player's eyes via script.
- The camera follows that transform due to the cinemachine "follow" thing.
- The head/body rotates towards the direction of the camera.
- The weapon tracks the position of the camera, keeping it smack center in the frame.
I'd be super delighted by this behavior if it weren't for one issue: The weapon jitters on screen, as if it were lagging one frame behind the position of the camera.
I think this is due to the fact that moving the camera moves the head/body, which in turn moves the camera as the followed transform is a child of the head. I think that animation rigging doesn't have the information on the true final transform of the camera until the body has moved, which happens in response to the camera moving, one frame later.
Does any of that make sense? Am I thinking about this correctly? What are my alternatives?
Here's a video for some visual context on what this looks like.
Definitely seems like a problem with the order things happen in, yeah
Not very familiar with cinemachine but I think there is a setting for when the camera calculation happens (update, lateupdate etc.)
I personally like to explicitly control all of this in code. This way I can understand the execution order better. It's all just about modifying some transforms anyway
A good tip for debugging this type of stuff is to manually set your framerate low so it becomes more obvious. You can use Application.targetFrameRate
Its not clear from the video but does the jittering happen when you turn sideways? I only see it when you are turning up-down
Yeah, I've messed with that, but none of the options really solve the problem.
I almost feel like I'm trying to get the engine to do something impossible: move this object (the followed transform) to this position, react to that by moving camera to that position, react to that by moving the skeleton to some position derived from the camera (the skeleton), then move the camera again to the new position. Then expect all of that to happen in the same frame.
Nope, and I think that's because I don't do any fancy rigging stuff with sideways look, I just rotate the rigidbody.
i.e. I don't move the camera in relation to animation which I think is my race condition?
Yeah the camera should only need to be positioned once
I cant think of the correct solution right now, mainly because I dont use anim rigging or cinemachine and not sure when/how they execute
No worries, I appreciate you helping out. I didn't know the framerate trick, which will be super helpful now and in the future I imagine.
I'll try and see if I can reduce the camera positioning to just once in this flow somehow
Cinemachine has a property field for execution timing. Usually you do want lateupdate, but if you're moving it on a physics body try updating at fixedupdate time
also make sure you got your physics body interpolating
Already messed with that to no avail π
Spline adjustment
No dice π¦
It seems like animation rigging just can't catch up to the camera's children. Setting the camera to fixed update seems to fix the desync but then my camera is on fixed update π
Are you sure, you are not double rotating something, like a parent and its child at the same time and therefore, it fights with local vs world rotation?
I don't think so. In my latest test I stripped my controller down to just the gun as a actual child of the camera and the hands with a two bone IK constraint to the gun and the hands are now lagging behind one frame
I fully detached the camera from the skeleton and was still able to reproduce the issue. In this test I basically just had the script to drive the camera and the IK constraints to the gun.
Nothing besides the camera was rotating
Did you just for testing purposes create a setup with a normal camera instead of Cinemachine?
Is it the bigger the game, the longer the build time?
In terms of building to publish
would you expect the opposite? π
Well the alternative I figured would be no relationship π
well both size of assets and amount of code contribute to build times in their own way
Got it, thanks!
Just confused because I just made my first project. Super small, 1 scene, and it took 30 minutes to build haha
Makes me wonder about progressing onto bigger games lol
Might be the first build tho?
Yeah it's the first build
I guess that takes longer!
?*
Complete beginner here lol
yep, cause its generating a lot of temporary files it will reuse later, like shaders and what not. But even that should not take 30 min on a small scene. But I dont know your setup and what you decide is being a small project π
I have now made some minor changes to it. Is there a way to apply these changes to the existing WebGL build? Or I will have to build and publish again from scratch?
how big is your library folder?
i had an issue like this after updating to unity6
yea u need to rebuild
guys how do i make this condition not to cause error when switching between animations?
onGround && animator.GetCurrentAnimatorClipInfo(0)[0].clip.name != "animationName"
subsequent builds should be a fair bit faster
It would help if you showed us the error
I do know that my WebGL builds still take a while to do the WASM compilation every time, though
As for applying changes: Unity doesn't provide any kind of patching system on its own; it just creates an entire new build
If you're publishing on Itch, its "butler" tool can upload just the diffs
very useful!
Steam, similarly, can upload a patch instead of reuploading the entire build. But you're probably not publishing a WebGL game on there :p
IndexOutOfRangeException: Index was outside the bounds of the array.
Check the length of the array before you try to access it
pretty standard array out of range error
e.g.
onGround && animator.GetCurrentAnimatorClipInfo(0).Length > 0 && animator.GetCurrentAnimatorClipInfo(0)[0].clip.name != "animationName"```
(I would use an intermediate variable here so the code isn't completely unreadable like this, but this is the gist)
this is also probably creating an extra array, which is very wasteful and inefficient
does this really work like this? if first condition is false than it won't check the other one?
Yes, that is the magic of the && operator
C# also has a & operator which will always evaluate both sides
both of them work as a logical "AND", but && is called the "short circuiting" AND operator or "conditional local AND"
You can find more info here https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/boolean-logical-operators
thank you s much, this is really useful
Has anyone here started using unity's new Behavior tree/graph yet? I'm getting some weird behavior when I try to make a simple custom action. I drag and drop blackboard variables (just a gameobject reference) onto the behavior agent, but in the action it says the reference is null as soon as it reaches it in OnStart()
it says which reference is null?
Show code and show the error?
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
In the behavior agent of the NPC I've added these just by dragging and dropping
And the graph is very simple so far, just wanted to test the behavior graph to see if I want to convert my current npc state handler to use behavior graph instead.
I watched a few videos on it, and I've seen it be used by dragging and dropping references, so I'm pretty confused as to what is removing the reference. That being said it's pretty new, so it's hard to find a lot of information on it
What is the exact error? Perhaps the object is being destroyed.
as soon as it reaches
root = Root.Value.transform;
it throws a null reference exception
I need to see the actual error in your console.
Okay, so it's not an error about trying to use a destroyed unity object
I can still see the reference in play mode on the behavior agent component
Do any of your variables work?
yeah the Self and Target work
well, actually:
if (Self.Value == null || Target.Value == null)
return Status.Failure;
which is weird
so yeah, they aren't null
Cos the target was added by me too in the same way as "Root"
I don't know if it's some editor bug or what it is
yes
You shouldn't be able to assign that at all. I wonder if this is a limitation of the BlackboardVariable type...
A prefab cannot reference a scene object.
Well the component is only on the non prefab object in the scene
You have to provide the reference after instantiating the enemy.
This was purely for testing
It doesn't matter if the scene objects happen to be prefab instances or not
The Root is a child of the gameobject that has the behavior agent
oh, sorry, I got "Root" and "Target" mixed up
The target will be some "Detect target" action in the future, but for now I just wanted to get it working at first π
Root for sure should work
But that's a bit odd. I would expect you to not be able to assign the Target variable if:
- The Behavior Agent is on a prefab
- The "Body" object is in a scene
Well I only put the behavior agent on the scene object for now, it isn't instantiated or anything right now
that's why I can assign the target since I am not changing the actual prefab right now
Ah, gotcha
hmm maybe it has to do with this
The target is highlighted in bold here but root is not linked or something
I don't have much experience with the behavior agent system..
but I noticed that "Root" is being rendered differently than "Self" and "Target" here.
yeah
ok yea that was it lol
idk why it didnt do that for Root but did with Target
so I have to link the variable
and it works
well thanks anyways for being my rubber duck π
Yeah it could be
Also noticed there's no rigidbody blackboard variable, wonder why that is
another problem, each time i run the game i get this error
Invalid editor window of type: UnityEditor.FallbackEditorWindow, title: Failed to load UnityEditor.EditorApplicationLayout:FinalizePlaymodeLayout ()
you should not be using UnityEditor namespace in a build, it does not exist
REset your editor layout
"Self" is definitely special. The package code ensures that one always exists
Yeah Self was on the behavior graph by default
Ok I think maybe I know what happened
I think maybe my Root was a transform at first. If I try to create a new action and they are all gameobjects, it autolinks
seems like it doesnt like transforms for linking
Well it did after, but even now if I create a transform blackboard variable, it doesnt want to autolink it when you type the definition of the action
Interesting.
for example here I created MyTransform
but as you can see it autofills Gameobject in the action, but the transform isnt
thanks again
I guess they want you to use GameObject instead of Transform (since they do always go together)
must be a bug with Transform then, I just tested with float and it autolinks there
Is Transform even an option in that list?
it is
wait, of course it is; you already did that
Weird
it seems very limited what it auto fills out though, seems like it's just gameobject and maybe the basic types
tried with AudioClip and a monobehavior script too and none of those get filled out
i have to stop before i get nerd-sniped any harder haha
didn't see anything too obvious in the code
Hello!
Is there an existing way for making this (but 3D):
I want a kind of navmeshsurface that bakes a bit like if there was a cloth over the objects
(in the quick paint I did, the **black **part is the ground & its objects, and the **red **part is the surface that elements could use for calculations)
(for giving 100% of the info, this is for moving the root of a procedurally animated
crawling-thing)
Well this looks like a 2d thing first off
So you'd need NavMeshPlus
And Navmesh uses an agent that has a radius so it should kinda work that way out of the box
Hmm ok I think I'm not clear enough
(but 3D)
smh praetor
I'll try to explain myself better: The image shows a front view (NOT top view). And it is 3D
Afaik navmesh doesn't handle anything in the "vertical" axis really
So what I want is kind of a surface that would look like a cloth was put on the whole level
navmesh surface can bake at any angle
It would be reasonable to create a surface that doesn't tightly stick to a visible object
(a bit like a terrain that encompasses everything under)
You know, mentioning terrain gives me an idea
you could figure out a sampling process that gives you this "smoothed out" surface, then use that to set the height of a terrain that you then bake
It's a bit roundabout, but that saves you from having to figure out how to generate the navmesh on your own
Honestly if it isn't even a navmesh it would be OK to me
The main thing is this sampling process hahaha
The process could actually be pretty simple
Create a heightmap from your world -- so, basically, shoot raycasts straight down
Next, blur the heightmap.
You'd want to do something that never reduces a height, though
Maybe blur it and then take the maximum of the new and old pixel values
Bro this is genius
plug that heightmap into a terrain and you can bake a navmesh based on its collider
you could also create a mesh out of it, I guess
but the terrain does that for you
This could be a good place to use a compute shader, but I'd start out with a script and a modestly-sized heightmap
WordTyprSentence.cs in com.unity.behaviour have code of this wizard, seems like only value types are supported and GameObject for auto suggestion since only those gets pulled from blackboard asset for suggestions
Hey everyone, I need help wrapping my head around this issue. I have a 3d grid of size 1 for objects and another grid of size .5 for volume. If I create a cube (center pivot) in the first grid I would then need to create a 2x2x2 set of points in the second grid. The problem is that the 2 grids aren't aligned in world space and I'm not sure how to do deal with the offsets in a way that won't cause problems. Anyone dealt with anything like this before?
Use Unity's built-in Grid component.
Convert to and from grid coordinates with myGrid.CellToWorld and WorldToCell
You can convert from one grid to the other with:
Vector3 worldSpace = grid1.CellToWorld(coordinateInGrid1Space);
Vector3Int coordinateInGrid2Space = grid2.WorldToCell(worldSpace);```
@leaden ice I was using those originally, but I moved away from them for some reason. I'll take a look at them again.
the nice thing is they basically handle all the scaling, rotation, translation etc of the grids automatically
i.e. if you scaled, rotated, or translated the GameObject the Grid is on, it will be respected.
Well I am doing a lot of rotating/scaling ect on these objects
that's been a whole other issue
Are there any downsides to Unity's grid system?
I guess the fact that it's a Component and requires a GameObject?
also if you use hex grids the coordinate system they use is weird
That's not a dealbreaker
I really like working with grids
they give you a new coordinate space and make it very easy to reason about that coordinate space
Hello, i have a problem with facepunch steamworks api. When i try to upload a folder to the steam workshop it gives me InvalidParam no matter what. I have tried changing the lenght of the title and description, removing the image, changing steam cloud storage limit, activating ugc on steamworks. I just can't get this to work properly, it always says InvalidParam
async void PublishToWorkshopAsync(string Path)
{
var result = await Steamworks.Ugc.Editor.NewCommunityFile
.WithTitle("Test world")
.WithDescription("Workshop test")
.WithContent(Path)
.WithPreviewFile("C:/Users/Username/OneDrive/Desktop/test/test.jpg")
.WithTag("Level")
.WithPublicVisibility()
.SubmitAsync();
if (result.Success == false)
{
Debug.LogError("Error while uploading");
Debug.Log(result.Result);
}
else
{
Debug.Log("Succedss workshop");
}
}```
Thanks
What specifically says invalid param?
A pretty big revelation I had is that I don't need to think about things like "how do I figure out how much to move based on the size of the object?"
I just need a fixed move in local space
the Transform will figure out what that means in world space
a more clear example: when snapping together modular pieces, working in local space makes things trivial
I have a script that scatters objects on a flat surface. I realized that I literally do not need to care about how that surface is positioned, rotated, or scaled, as long as I work in the correct coordinate space
it doesnt tell me
it returns a result
and it says invalid param
I'm asking where you're seeing that
Debug.Log(result.Result);
How so?
https://wiki.facepunch.com/steamworks/Ugc.PublishResult
alas, there's no more context than the Result enum here
I have a "reference" Transform that's used to define the area in which I scatter objects (using a Bounds struct). I calculate a local position to put each object at and only go to world-space at the last second (when I'm actually spawning the object)
I wonder if it's breaking because you gave it an invalid filepath for WithPreviewFile
unless your username is literally "Username" π
I wish Transform gave a clear way to go from world to local and vice-versa for rotations
there has to be a .25 offset somewhere between my size 1 grid and my .5 size grid
or I need to not be using center origin for everything
you can just move the object with the Grid component by .25
that's what I was saying before about it respecting the position, rotation, and scale of the object
Debug.Log(result.Result); // InvalidParam
Debug.Log(result.NeedsWorkshopAgreement); // False
Debug.Log(result.FileId); // 3409303111
i changed the username π€«
i already checked this
darn
https://partner.steamgames.com/doc/api/ISteamUGC#SubmitItemUpdateResult_t
k_EResultInvalidParam - Either the provided app ID is invalid or doesn't match the consumer app ID of the item or, you have not enabled ISteamUGC for the provided app ID on the Steam Workshop Configuration App Admin page.
The preview file is smaller than 16 bytes.
I just discovered something pretty helpful!
private void Start()
{
Destroy(gameObject, 3f);
}```
You can destroy something after some time in the Destroy method
Makes it very easy to despawn my bullet prefab after it gets instanced
the app id is correct and the preview is bigger than 16 bytes, i also activated ugc
soemthing really goofy happened
a lot of blank maps just got added to the workshop
0 bytes and no previews
Ye it can be very useful. I mainly use it for particle effects like explosions or things I don't use that often, but I still want to play out their effect before destroying it/cleaning up.
For bullets though (or other things that are frequently used) I would normally use object pooling
Yeah, pooling is on the list of planned features, but not too much of a concern for now
I should put a trello board together, tbh
On the topic of bullets, a ScriptableObject would be an ideal data structure for projectiles, right?
Depends, it's def an ideal data structure for storing data that doesnt change much
I'm trying to use newtonsoft json to populate specific fields of an existing array, leaving missing members alone. Unfortunately it is assigning default values to missing members and I have no idea why. I've tried every setting and attribute which should signal newtonsoft to ignore missing members, but it refuses . Am I missing something obvious here?
[System.Serializable]
public class GameRefs
{
public SceneInfo[] SceneInfos;
}
[System.Serializable, JsonObject(MemberSerialization.OptIn, MissingMemberHandling = MissingMemberHandling.Ignore)]
public class SceneInfo
{
[JsonProperty("Header")]
public string Header; // correctly populated by newtonsoft
[JsonProperty("Body")]
public string Body; // correctly populated by newtonsoft
[JsonIgnore]
public Transform Transform; // nulled by newtonsoft
[JsonIgnore]
public float ScanAngle; // set to 0 by newtonsoft
[JsonIgnore]
public Image3DScene Scene; // nulled by newtonsoft
}
public GameRefs Refs; // Serialized as a monobehaviour field
// Json with just the Header/Body members
var json =
@"
{
""SceneInfos"":
[
{
""Header"": ""ElC-39A"",
""Body"": ""Test""
},
{
""Header"": ""ElC-39B"",
""Body"": ""Test""
},
// ... omitted for brevity
]
}";
var settings = new JsonSerializerSettings
{
MissingMemberHandling = MissingMemberHandling.Ignore,
};
JsonConvert.PopulateObject(json, Refs, settings);
// Still assigns default values to missing members
you try this?
JsonIgnore attribute should usually be enough, are you certain that newtonsoft is specifically nulling these fields? If you set them to some specific value in the inspector, is your loading of that file then resetting those specific values to default? (being null or 0 in your case) if so, how are you loading the data? Does it do the same if you make a constructor for the data your loading? AFAIK JSON basically does the equivalent of new T - and Unity will default serialized types automatically so float will default to 0 by Unity, and Transform will default to null by Unity if they are public/serialized to the inspector, so JSON calling new T would also cause Unity to default those values (without a defined constructor)
I have. It seems that's for serializing, not deserializing
It is relevant in both places
but only if you have a [DefaultValue] attribute, I think
Roger - well I have tried it with no luck in any case, tho I probably haven't tried every permutation of applying that setting (to the JsonSerializerSettings, attribute on array field, attribute on array element type, attribute on array element fields etc)
@soft shard
The array is serialized on a Unity component. I want to populate the Header/Body members for localization reasons, but the other fields need to be left alone since they are configured in the inspector. So the array is prepopulated with important data, but after calling JsonConvert.PopulateObject the missing members are assigned default values (as shown in second screenshot). If I don't call the function the fields not lost so it isn't something else.
I tried adding ObjectCreationHandling = ObjectCreationHandling.Reuse to the JsonSerializerSettings in the hopes it would not construct new instances of the array elements, but that did not work. I figured PopulateObject would not create a new instance since it's meant to deserialize over an existing object and a new instance couldn't be assigned to the original unless the target object was passed as a ref parameter, tho I guess it could be doing that for the array elements within the passed GameRefs object's SceneInfos array
I added a trace writer to the serializer settings and it is not logging anything about the missing members, so it seems to be skipping them as intended. I'm guessing it is creating new instances of the array elements and losing the other serialized fields in the process as you suggested @soft shard
2025-01-17T15:57:59.531 Info Started deserializing GameRefs. Path 'SceneInfos', line 3, position 17.
2025-01-17T15:57:59.536 Info Started deserializing GameRefs+SceneInfo[]. Path 'SceneInfos', line 4, position 5.
2025-01-17T15:57:59.537 Info Started deserializing GameRefs+SceneInfo. Path 'SceneInfos[0].Header', line 6, position 21.
2025-01-17T15:57:59.537 Info Finished deserializing GameRefs+SceneInfo. Path 'SceneInfos[0]', line 8, position 9.
2025-01-17T15:57:59.537 Info Started deserializing GameRefs+SceneInfo. Path 'SceneInfos[1].Header', line 10, position 21.
2025-01-17T15:57:59.537 Info Finished deserializing GameRefs+SceneInfo. Path 'SceneInfos[1]', line 12, position 9.
...
Do you know if it's possible to circumvent this? Maybe ObjectCreationHandling = ObjectCreationHandling.Reuse needs to be put on an attribute somewhere rather than in the serializer settings π€
This does not solve it either π
[System.Serializable]
[JsonObject(
MemberSerialization.OptIn,
MissingMemberHandling = MissingMemberHandling.Ignore,
ItemIsReference = true,
IsReference = true
)]
public class GameRefs
{
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Reuse, ItemIsReference = true, IsReference = true)]
public SceneInfo[] SceneInfos;
}
To test if newtonsoft was reassigning references I stored a reference to the first array element before the Populate call and then checked its equality against the first element afterwards, and they are not equal
Im not sure if its possible to take over what happens when you add a new element to your array, or if using a constructor for SceneInfo that only populate the 2 fields will work for you, otherwise the only other option that comes to mind atm may be less ideal, in using JSON to create a "clone" and copying the data over, effectively doing the population yourself, something like:
var data = JsonConvert.Deserialize<SceneInfo>(...);
for (int i = 0; i < data.Length; i++) { someMono.actualData.infos[i].fieldA = ...; } //and so on for all relevant fields
or something similar, except using the data from element 0 of your actual mono data, to re-assign the 3+ missing fields that the default constructor may be setting, though maybe there is a better way im not familiar with or thinking of atm
Thanks! I ended up writing this function. Not happy about it, but it works haha.
void PopulateArrayInPlace<T>(string json, T[] targetArray)
{
var jsonObject = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
var sceneInfosJson = JsonConvert.SerializeObject(jsonObject[jsonObject.Keys.First()]);
// Deserialize the JSON into a temporary list
var tempArray = JsonConvert.DeserializeObject<T[]>(sceneInfosJson);
if (tempArray == null || targetArray == null)
return;
// Update existing array elements in place
for (int i = 0; i < targetArray.Length && i < tempArray.Length; i++)
{
// PopulateObject updates existing instances
JsonConvert.PopulateObject(JsonConvert.SerializeObject(tempArray[i]), targetArray[i]);
}
}
Well, at least it works lol, glad you found a solution
Alright, I got this down to a tiny repro with basically nothing but cinemachine and animation rigging:
- Gave MainCamera a cinemachine brain.
- Gave CinemachineCamera a cinemachine camera, with a pan tilt bound to input system/mouse look.
- Created an empty object, "Sphere", gave it an animator and rig.
- Created a "model" child of "Sphere" containing a sphere mesh renderer.
- Created a sibling "Rig 1" object containing a multi-parent transform constraining "Model" to the cinemachine camera.
- Observed the exact same jitters (vid incoming).
Does anyone know what's up? The problem starts happening the moment I introduce the cinemachine into the mix.
Constraining to the main camera (if no cinemachine brain on it) will track beautifully.
LateUpdate/SmartUpdate makes no difference.
Probably super easy mistake but how do I add materials to the materials array of a mesh renderer? It doesnt let me add them saying the array is of a fixed size so whats the intended way of adding some?
I believe you will have to make List<Material> variable where you store the meshRenderer.materials and then add your material to that variable before storing it using meshRenderer.SetMaterials().
Untested:
var renderer = GetComponent<Renderer>();
List<Material> mats = renderer.ToList();
mats.Add(yourMaterial);
renderer.SetMaterials(mats)
Ya sure you have multiple material slots on the mesh data?
yes, this is an array
Are you working with the prefab or the actual import instance
Ill try it like that I was AddRange() ing an array instead of Add() ing a list
Actually it looks like you can just drag it onto it unless you mean in code
Yes I mean in code I have the 1 prefab and the material for parts of it are set in a ScriptableObject so now I need to transfer it from the SO onto the prefab in runtime
Add() doesnt even exist as a method on materials
Add is on the list
Well yeah, it's an array
Well its not a list its an array
As the error points out, arrays are of fixed size, once you create one, you cannot change the size. You can always create larger array, copy elements to it and add the new elements to the empty slots
yes I realize that...
ToArray ;)
thats literally whats giving the error then and doesnt really has much to do with the issue
You've not posted the error or the code
It's very much a function you could choose to use
saying the array is of a fixed size
Thats the error, wdym I didnt post it
That's a sentence you wrote
just make a new array with the objects you want and reassign the variable
A sentence telling you what the error is
That's not an error
you get back array -> make into list -> append to list -> make new array from list
doesnt matter how you make the array, just get the final list of crap you want in there and set it to the property
So you wanna tell me an error is not just a string of what went wrong, oh wait, thats what I sent you
Looks like you don't want any help
I do what I dont want is snarky remarks of people that dont intend to give me any
An error is a formalized string that usually has a stack trace.
now that we're done adding elements to arrays, anyone have ideas on how I can make my camera not suck? π₯Ί
Asking for the error and your code is very much valid request. Preferably you should have provided them in the first post already. We are just guessing what might be wrong and telling how it should be done right, thereβs no way to actually tell why your code doesnβt work if you donβt provide it
We also donβt have the context of your code to work with so the solutions provided may not be helpful in your case
#πβcode-of-conduct clearly states that you should have those in your posts when relevant so asking for them is not snarky in any way, it just avoids confusion if you just provide them
ToArray wouldn't produce an error, which is what I was going to point out with both. "literally what's giving the error..." is the real snark
"NotSupportedException: Collection is of a fixed size"
Now that really does sound like its put to the sentence "saying the array is of a fixed size"
I didnt give you my direct code to avoid an A - B problem because maybe my approach is completely incorrect but rather explained what Im trying to do, sure have a single line of code that mirrors what I said Im trying to do
myMeshRenderer.materials.AddRange(mySOReference.materials);
So what Im understanding is the intended way is something like this:
List<Material> Materials = new List<Material>();
Materials.AddRange(SOReference.Materials);
Materials.AddRange(myMeshRenderer.materials);
myMeshRenderer.materials = Materials.ToArray();
I must say I dont like this code with all the casting I was hoping someone knew a better way than me casting between types all day
there's not a single cast in this code
There's no casting here, but yes that's one way to do it. Though it's weird to resize the materials array
I have 2 array, make those arrays into a list, make the list into an array
The materials array should be the size of the number of submeshes, which is generally the size that it imported at
anyway, there should be cuter functions you can use for this if that's what you're after
as you know the final size, there is no reason to use a List here at all
but it's all generally the same thing
But you can use GetMaterials and SetMaterials with only lists too
that may be but for this specific usecase I removed the material from it (in this case its just 1) to duplicate it and change the colors on it, and that new one then needs to be applied to the according prefab, where I spawn multiple with different colors
Though I assume just setting the material array directly would work?
Sure
I honestly don't follow what you're saying here
I have a creature
that creature has a Material that makes it blue
I spawn creatures according to my ScriptableObjects
this SO decides what color it should have so I put the material on that instead
So I end up with the same prefab having the same mesh but that mesh can get either of many Materials depending on what SO I chose
Well since I removed the material that I recolored and have it as a Material[] on the SO now I need to add the Material[] of the SO back onto the MeshRenderer, else it just wont have that material obviously, and the question now was for the proper way of doing so because as I mentioned above I dont like the constant back and forth on the different types and just adding doesnt work because of fixed array sizes
Gotcha, yeah. I think all of that makes sense but there's not really a way around it.
You can't resize an array. You have to make a new one in the desired state.
There's a couple of different syntaxes by which to do that, some approaches are slightly more efficient than others, etc.
but ultimately you need to put a new array in there, and that array needs to have more elements than either of the arrays you're sourcing elements from.
like for example, you don't need to go array -> list -> array.
I think that the firstArray.ToList().AddRange(secondArray).ToArray() is the cutest/most legible approach
Yeah I think I found a way that while not totally making me happy I feel relatively okay about
but it's slightly less efficient than the alternative:
make new array of size firstArray + secondArray then iterate over each element in each array, setting them in the new array
that said it doesn't really matter, it's a little extra pressure on the GC because it will need to collect the intermediate list but shouldn't take precedence over readability
What did you end up doing?
foreach(MeshRenderer wingPart in WingParts)
{
Material[] wingMaterials = new Material[Moth.Wings.Length + wingPart.materials.Length];
int i = 0;
foreach(Material wingMaterial in Moth.Wings)
{
wingMaterials[i] = wingMaterial;
i++;
}
foreach(Material wingMaterial in wingPart.materials)
{
wingMaterials[i] = wingMaterial;
i++;
}
wingPart.materials = wingMaterials;
}
oh sick
yeah basically the only two approaches
Reading .materials creates a copy of the array, so now you're creating an array just to get the length
aint that great
your code is a lot uglier than it would be with just the toList().toArray(), but I mean, I never have to read that again π
why would .materials be creating a copy? You're just accessing the materials property
because unity magic
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Renderer-materials.html
Note that like all arrays returned by Unity, this returns a copy of materials array
His 'ugly' code is a lot more performant than your 'pretty' code
but it will do that anyways at some point, at latest when I set the new arra yso I should just cache it in general then I suppose
a lot is a huge overstatement
but yeah, I did say there were two options
Or will the cached value also be copied?
The best part is when people use mesh.vertices.Length in a for loop and allocate a massive array, a massive amount of times lol
that's so dope, tbf that is the last thing I would expect
foreach(MeshRenderer wingPart in WingParts)
{
Material[] GOMaterials = wingPart.materials;
Material[] wingMaterials = new Material[Moth.Wings.Length + GOMaterials.Length];
int i = 0;
foreach(Material wingMaterial in Moth.Wings)
{
wingMaterials[i] = wingMaterial;
i++;
}
foreach(Material wingMaterial in GOMaterials)
{
wingMaterials[i] = wingMaterial;
i++;
}
wingPart.materials = wingMaterials;
}
``` this would fix it and only create 1 copy instead of 2 right?
Do you know if there is some sort of code analysis tool that would give warnings on things like these? I don't know if there are some unity specific ones
No, though Rider has a lot more warnings than VS/VSC
right now I'm using sonarqube
just be aware that you are responsible for destroying those materials
This really sounds like your arrays are constant size anyway and you could be refilling them instead of reallocating them every time... That being said, since you just seem to be swapping "color", this sounds like it might be better suited to MaterialPropertyBlock and changing individual properties than re-assigning materials
Also half of those materials will be copies, and the other half not-unless the SO ones are being instanced somewhere else
With URP and HDRP there's very little use of MPBs any more, as it breaks the SRP batcher
Hi, Im having a problem: When I build and run my game from the editor, it works perfectly but when I close it and then start the .exe manually or just build and start the .exe manually, it loads the "Made with unity" and then instantly crashes. My only idea on why this could be is because I worked on settings (resolution settings) with playerprefs
Also: Im using steamworks, I have my own steam app id and its connected to steam, but that wasnt hte issue, before I added the settings it worked fine
have you made a development build and checked the player log?
yes, the player log didnt show any error
are you doing a mono or il2cpp build?
mono
but I do not think switching to il2cpp will change much, i mean i dont have much yet, and as i said building and testing worked perfectly everytime before I added the settings
i will quickly remove everything about the resolution thing and try it out
I'm concerned by the lack of info in the player log, that indicates a severe error
I mean it could be that I overread sth but this is the log
ill do some more debugging and report
Maybe try attaching the debugger. To the build or checking the crash logs.
ok I did some debugging and testing and its because of steam initialization, i have my steammanager here:
So it might be related to my appid, since the "RestartAppIfNecessary" is invoked
this is so weird, i did build and run again and it works
now i click the .exe file and it doesnt work
One thing that bothers me is that you only catch specific error in awake. I'd catch a generic error, output it to the console and quit instead.
catch (System.DllNotFoundException e)
Also, I'd debug the issue like this: add code that waits for the debugger to attach in awake. Then attach the debugger and step through the code.
Hey guys,
How can I define an area of my UI (by stretching a panel over the area, for example) and have that panel be invisible, detect some pointer events like Enter and Exit, but be transparent to all other events like mouse clicks?
probably
Oh you're asking how, well start on something and probably seek help when you can offer something to work with
Why if i change global volume component values in game its not changing it. but if i change it when game is stopped it works
I'm trying to add a .editorconfig to my unity project, but VS doesn't seem to be using it. I want it to essentially auto-format my code or give a warning for things like modifiers not being in order. What might be the reason that it isn't working? I have a .editorconfig file at my root unity project level (Assets, Builds, Library, Packages, etc.)
we can't possibly know without further info.. we are not psychic lol
So i am making a unity 3d fps multiplayer game with photon fusion and i have stumbled upon a problem where the other players can not hear your footsteps, i have tried using photon [Rpc(RpcSources.All, RpcTargets.All)] but this did not work. Anyone that can help?
also photon server is pinned
Hi is there anyway that Unity supports Webcam eye tracking? My team is thinking of developing a game with blinking but we are having issues finding anything about the subject. Most searches lead to adroid stuff or like oculus. But we want just the webcam
You'd probably need some type of model trained for this specific purpose
we loked more into it and it seems like our best bet is this openCV package: https://assetstore.unity.com/packages/tools/integration/opencv-plus-unity-85928
its really annoying cause theres been a bunch of development with XR tech but like webcam tracking has been left to rot lol
if you want something more specific
https://huggingface.co/unity/sentis-iris-landmark
You can use Unity sentis and use Onnx models
mmm im strugling to really implement this
we might just have to work on something elese (its for a game jam)
super sad how hard it is to find stuff on this
yeah working with these models isn't trivial , at least unity makes it easier to load them. Check quickstater on sentis
yes you should pick a simpler project lol
we just want blinking man T_T
Do you need to use unity at all, as hte gamejam is about unity, or could it be anything?
You could also look into web solutions and run your game as a webgl export. than you could hook the web part to the unity part with calls
we wanna make a run and gun game with blinking as a mechanic
like you blink and teleport as a little gimmik
then your gimmik might take 75% of your time of the game jam π
unity also lets you just use python libraries
yeah lmao. Were about to abbanodn it if we can't get this addon to work
it's so werid cause like people have done this before??? but liek a bunch of stuff is deprecated
this is a two week game jam so we have a good amount of time which is why we are exploring it
pepole who make it work don't bother writing guides for it
most of it is on mobile devices, which is still working
its not for mobile, I guess?
no sadly not. We need a webgl build too
then look into web solutions for facetracking and just send messages to the unity container
"Support for the Python Scripting package is scheduled to end as of Unity 6.1." sadly π
bummer
how would that be a webgl build though?
like look I've made around 21 games before I got no idea how I'd do that stuff lol
your unity game is a webgl build. Thats an index.html with a webgl container. and you can send and receive javascript messages to control either the page or the container
not that making a lot of games is credentials im just saying
So, your web plugin detects blinking, you can send the message to unity and do your stuff there
still need some type of model to you can use maybe JS has tensorflow
my teams brain is too small lmao im gonna be real
But thats out of scope from this channel then, cause its not unity relevant to get facetracking running in web π
tbh you can just use one specific to blinking
like theres a hundred things with like mobile and shit but like why no webcam one lmao I just wanna blink
I think you got the leading ideas, that can help you. The rest is up to your team π
Dude im gonna be real doing it through webgl java scripting does not seem really that viable for us cause we would have to learn the xr stuff on top of the browser scripting through unity lol. I do apperciate the help though my guy. We are probably just gonna move on with a different idea if we can't get this openCV addon to work
π thank you for the wisdom my guys
In the end you have to learn
β’ WebGL JavaScript to C# Calls
β’ Install a javascript package and run it
β’ Fire the call from 1st step with the recognition from the package
β’ React to the event in Unity
Or you could pay someone who did it probably https://assetstore.unity.com/packages/tools/camera/imagine-webar-face-tracker-279828?srsltid=AfmBOoop7a75d4wEzFFWarlZHiAilGP-_e9vFgbbsxpzFwWDGrwnWGGY
also wouldn't doing it through javascript make testing really really slow? cause we would have to build it every single time
There is also a tutorial, but might be for mobile, not sure: https://learn.unity.com/course/create-with-ar-face-filters?uv=2022.3
In this course, you will learn to create your own augmented reality (AR) face filter apps using Unity. You will create multiple face filter projects from start to finish that are compatible with both Android and iOS devices. The first app youβll create will overlay textures, animated 3D models, particles, and other effects on the userβs face. T...
But as you keep argueing, what COULD slow you down, just decide for your own π Go for it or not.
If its not important to the game, its not important
cool thank man
you should use OpenCV but there are only 2 options c++/python for easy set up, rest will be troublesome or deprecated
i tryed with js some years ago, it was huge pain
Hey there, I've been trying to connect my MySql Database to unity via ASP.Net Core API (Been following Tarodev's tutorial). It's been working well until I tried introducing the Identity package in the API. I can't use the user account table as a class in unity, but I need to store all data in reference to their user, so I don't know how to progress from here. I thought about creating an additional player table, which basically just copies the users and is referenced with their ID, so I could store additional app-specific info there, but I really don't know whether that would be good practice or just bite me in the knee in the long run..
Anyone got some ideas?
Can you tell a bit more about the project, what architecture decisions have you made and why? Accessing a standalone DBMS from a Unity app directly is in some cases not a good idea. And if you are in that case, your problem may be solved by doing the βright thingβ.
how can i rotate towards a target rotation using rb.angularVelocity
google has come back with nothing and everything i've tried has just turned into this in some way or another 
I'd base my solution around this: https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Vector3.SmoothDamp.html
Try something like
rigidbody.AddTorque(Vector3.Cross(targetForward, rigidbody.transform.forward) * speed, ForceMode.VelocityChange);
You need a perpendicular vector for torque which cross provides
If that doesn't work try switching the arguments in cross around I'm not too sure which way they should go around because quite frankly my brain is melted right now
Oh right uhh
targetForward should be (lookAtPosition - rigidbodyPosition)
oh right. i hadn't thought of trying addTorque
lemme try this real quick
Oh right uhh you might also want to increase the angular drag btw
This isn't a spring so it wont account for the angular velocity and it might overshoot a bit
I found 1.7 is a sweet spot
worked perfectly :D
Awesome!! Glad it's all good
hey everyone, am wondering... how does discord impliment code snippets and do you know if it has an api that i can use in my own applications outside of discord?
that's not a unity question. but afaik it uses highlight.js
Any good input on how to best organize a system for display sprites based on underlaying grid system. Would like to avoid a game object for each sprite. Is the standard tilemap the best option?
I'm very used from work to ReSharper, is anything similar widely appriciated and free for Unity?
I'm struggling to understand what ReSharper is
Seems like a bag of handy features?
What features does it have that, say, Rider doesn't already come with?
I don't know if free Rider already includes ReSharper, but yeah I mostly use it with vs2022
It provides utilities, formatting, enforces coding standards yadda yadda
I'm just reading this https://marketplace.visualstudio.com/items?itemName=JetBrains.ReSharper
And most of the things are already present in the free Rider version
Apart from some of the AI assistant stuff I guess
Time to always use rider out of work? I guess
I suggest trying it out π€·ββοΈ
ty
My migration to it was very seamless (from VSCode), mainly because it lets you import the keymap and other settings from your previous IDE when you start using it
Hey guys,
How can I define an area of my UI (by stretching a panel over the area, for example) and have that panel be invisible, detect some pointer events like Enter and Exit, but be transparent to all other events like mouse clicks?
So I made a encounter system for my game so I can easily create different enemy encounters. Now I want to add a encounter manager script that can handle the behaviour of the enemies.
But i'm not sure whats a good way to make it so that I can attach the script to the ScriptableObject in the editor since I can't just attach a normal script there.
[CreateAssetMenu(menuName = "Custom/Encounter")]
public class Encounter : ScriptableObject
{
public GameObject[] enemyPrefabs;
public Vector3[] spawnPositions;
public int minFloor;
public int maxFloor;
public EncounterManager manager;
public bool IsValidForFloor(int floor)
{
return floor >= minFloor && floor <= maxFloor;
}
}
you cannot do it in the editor. you will need to use either dependency injection from the EncounterManager or have the SO find the manager object OnEnable
well I cant attach a normal script but I can do stuff like make it the manager a scriptable object or attach it to a object, etc. Those are just a bit messy so I was wondering whats a good way to do it
yes, I already told you the 2 options you have
It turns VS into Rider. It also predates Rider.
That's what I thought heh
I've heard that ReSharper hardcore kills VS performance.
Doing something will always be slower than doing nothing.
If there is no net-value in the things that R# does for you, it should not be used
wait does unity not support priority queue?
Right but I've heard that it's by a lot, to the point that people advice against it.
Generally R# and rider help a lot with reducing refactoring effort, language misuse and paying down technical dept
That question makes no sense
If you are talking about this PriorityQueue, then no at the bottom you can see it's supported in .NET 6+, Unity uses .NET Standard/.NET Framework.
i mean the built in priority queue in NET
Canβt speak to that. Itβs also a bit of random info. However rider can definitely get slow. But at least to me in larger C# stuff, it pays off.
I don't mean Rider is slow, but specifically using ReSharper in VS is slow.
lame
I would expect they have the exact same effect since Rider, afaik, runs R#βs engine
Not from what I've been told by others, but eh I don't use either so I can't know for sure.
I want to create a camera system like in game Furi. it's a top down 3D boss rush game, camera centers on player, center of arena, midpoint between boss and player and so on. I could try to replicate it but i dont know exactly how it works, so i'm looking for tutorials.
If you are referencing another game, it would be good to include a link to a video of that game/said system.
Yeah we can all google it but this would give you better chances of getting help
Cinemachine probably has a lot of the features seen here, if you don't want to program it yourself
i'm fine with programming myself
seconding cinemachine
Which part are you struggling with? Do you have anything so far?
You didn't really ask a question yet
At its core, camera scripting is just about moving a transform
i was asking for guides where people have made something similar
i would suggest you try doing it without a guide and look for one if you get stuck
do you guys think its better to represent a grid as a 2d array or as a dictionary of Vector2Ints?
What are you trying to achieve? I'd say the first one is better over working with a dictionary
dictionary because best data struct
unless of course you have something fancy in mind
if its a fixed size grid then do a 2d or single dimension array as this the lookup is simply calculating the index
2d array without a doubt
π§
what's the cost of a null index though
none
assuming say you want a 100x100 grid
no pointer cost or anything of that sort at all?
no
just the memory being un used but its often worth it
Is all of the grid filled with something or is it sparse?
The use case matters
for the most part Unity makes all its grid with some dict, but it's because they're usually infinite
Yeah, with an array you are constrained to a certain size
I like how easy it is to represent a 2D array as a 1D array
[x,y] isnt too bad, but its added effort to deal with a second item
[i] is just so much simpler
And resizing it would be costly
yea if its not a fixed size then do something else or have small chunks of a fixed size
I think [x, y] is easier but AFAIK 1D arrays are more performant and can also be serialized by unity so I often go with 1D array and [y * xCount + x]
its not sparse, but from what ive seen 2d arrays dont support a lot of operations (like, linq stuff) which is slightly annoying
you know you can remap a 1D array to a 2D one with no extra cost
I think box did some testing in c#'s 2D array and apparently has some performance problems
Nah I don't, how does that work in practice?
I thought a 2d array is just syntax to do the a,b -> index for you
Have a look at the Array class docs
wait wha
then there shouldn't be a perf difference right?
I prefer single dimension and doing it myself as i needed to use said array in some generic stuff and 2d arrays cannot
Not sure what exactly I'm searching for
Heres a snippet of how I designed my custom grid/tilemap in my last project
i wouldnt suggest copying the code, just more as a way to show how youd store a 2D array inside of a 1D
code is gone but can only presume how the elements were accessed caused the perf difference
array[(y * Width) + x] its pretty much just this expression that matters
so 1d array thats a 2d array?
Does sound funny that a jagged array would be somewhat more performant but I forget all the details
How can I add sections like these to my script in the editor?
SerializedClasses
all an array access is in non managed languages is array pointer + index so if you access sequential elements frequently you benefit from less cache misses
but no idea what bullshit mono causes
[Serializable]
public class Damage
{
[field: SerializeField, Range(1, 20)] public int Amount { get; private set; } = 1;
[field: SerializeField] public CombatElement DamageType { get; private set; }
}
[Serializable]
public class Defend
{
[field: SerializeField, Range(1, 20)] public int Amount { get; private set; } = 1;
[field: SerializeField] public CombatElement DefendType { get; private set; }
}
...
public Damage Damage;
public Defend Defend;```
The default foldout is a bit less sleek than the one in the screenshot but yeah
"you got any more of those new lines?"
people just need larger monitors
not sure how much this helps, the yellow is if you had a 1D array, blue is the 2D array.
Say you wanted to find item 4, which would have the actual coordinate of [1,1], if you follow the white boxes (sorry if theyre badly written) you can get an idea of how it would work
i prefer attributes to be above fields and properties myself
really the 1D array should have been formatted like this, but for the sake of the diagram it might have been confusing
Still waiting for clarification on this. Didn't see anything related on the doc page https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/arrays
Ah maybe i should look here https://learn.microsoft.com/en-us/dotnet/api/system.array?view=net-9.0
sorry, my bad, looking at my code it seems this is extension methods I made myself to convert 2d indexes into 1d
basically using this #archived-code-general message
Well I mentioned that in the very message you replied to
It's extensions I wrote so long ago, I had forgotten that I wrote them, assumed they were built in
Happens
im late the convo but i have a 1d array for my dungeon grid and it was a bit difficult
mostly cause i didnβt look up a tutorial and didnt know 2d was an option
Just make methods that do the index conversion for you
yea i did
do you really need a tutorial to do such simple math?
but i place objects in the place of the array and i had to specify their spacing and everything in code
and then the rooms are connected by hallways
and they form a maze with specific rules
i mean i shouldve at least looked up how other ppl did it cause i had 0 clue what ppl usually did in those scenarios
turns out i did something sorta normal
There are 3 options when you need to deal with 2D (or nD in general) arrays:
- 1D array (
T[]) and map indexx, yinto indexx + y * w. - Jagged array (
T[][]) - Multidimensional array (
T[,])
Unfortunately multidimensional arrays miss out on quite a lot of optimizations, that they are even slower than jagged arrays.
Jagged arrays while faster than MD arrays, is likely to be slower than 1D arrays, because each row is a separate array on heap and likely to not be in CPU cache. Although whether this cache miss matters or not does depend on your access pattern.
Whether the performance difference between these 3 options are big enough to matter or not, is a separate question.
Need Help: is it possible to access or save values in cloud save using path to the data so that nested values can be easily accessed or only save load using dictionary like structure key and value.
I would add that the DIY 1D solution makes you feel like a boss, especially if you use a spiral index or some other neat pattern.
i ended up going with the dictionary anyway :/
being able to use a sparse grid might be useful in some applications
damn this version of C# doesnt use collection expressions either noooo
dictionary is bestest
not sure what you mean, "dictionary" is a data structure, "cloud" just means using a remote server.
if you are accessing data "from the cloud" you are still accessing it as a dictionary (if you are using json for example)
yes
i meant is it only restricted to getting value as key value pair or i can get value of any data or nested data using a path such as happens in firebase database which is a tree like data base
I am not super familiar with networking stuff in unity but i doubt there is such a restriction
i think its better if you looked at the documentation
well the examples they have is like using a dictionary not a path so i guess that might be it still thought there might be any other alternative way which they might have not shown. anyway thanks
Unfortunately multidimensional arrays miss out on quite a lot of optimizations, that they are even slower than jagged arrays.
Really? That would imply they're somehow even worse than storing every single 1D array separately.
Yes really, see benchmark: https://github.com/Treit/MiscBenchmarks/tree/main/MultiDimensionalVsJaggedArray
I haven't looked into the exact mechanism as to why MD arrays are so slow, but IIRC it has something to do with lower bound handling.
That's what I'm seeing on some StackOverflow post
That's so counterintuitive.
Yeah it's a bit unfortunate that a language feature created to solve that problem ends up not being used over a primitive hand rolled solution.
Good one, Stack Exchange. I'm not losing half an hour this morning
No drawbacks
Prevent Wallrun
Hello, I am making a new camera controller for my space game. And need a bit of help. I currently have this code here. I now want to fix my bug that the camera is wrongly rotated. For that this.planet.Vector3Down(transform.position) returns the correct down vector. How can I implement that it uses this down vector? As you can see in the video, the camera is rotated wrong
yes
How can I automaticlly rool it based on the down vector
The down vector dynamiclly changes
have you tried rolling it based on the surface normal?
no
i am new
can you help me with that
should i shoot a raycast
and then use the normals of the hit point
You need two vectors! The normal vector is easy, but you also need a tangent vector
I can explain more later β gotta run in a minuteβ¦
There was an issue I had with a college project involving setting the velocity of the player's rigidbody2d in coroutine functions
I set up knockback and wall jumping, which used similar scripts. However, both abruptly fell apart after working on my project for reasons that couldn't be fixed via code. (When the velocity of the rb is set, usually sending the player to the upper right or upper left, an outside factor ends up completely screwing with the rb, only making it go upwards for as long as the coroutine lasts. Print functions showed that the code was working, there was no restrictions on the rb's x position, nothing affected collision, but the x axis never changed during runtime.) I don't want to encounter this again if I ever use Unity in the future, so if anyone has some sort of input for me, I'd like to hear it.
well unless someone here has experienced the exact same issue, it's gonna be hard to debug from just the description without specific information
Sounds like a serious lack of skill/debugging issue
Just sounds like a code or configuration error
Sounds like a lot of guesswork unless code and other stuff is shared
Hey, I have a game where I store map representation using 1D array of tiles with some calculations. Sorry for late reply but I wasnt nearby PC earlier on. Maybe this will help or inspire you to create your solution: https://pastebin.com/Pqjq4mEi - look at Tile[] array and GetTileIndex method (note-code is not exceptional quality to say at least xD) @teal hare
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
!code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
i am using dotween and when i use my sliding script it makes it default to the center of the ui, how do i make it so it defaults to where it was when it was edited?
I meant a weapon attack collision like a sword slash or a whip.
What are best practices regarding animation + collision.
From what I've seen I can edit each frame of an animation and enable/disable a collider + set the collider manually to match the animation etc.
That is a lot of work, but it's also going to be consisten with the animation.
Another way is to simply have "sword slash" object and enable/disable it separately whenever we attack with a character.
Definitely with direct physics queries
not with colliders
You can use animation events to fire off the physics queries at the appropriate time in the animation
physics queries being raycasts?
https://docs.unity3d.com/Packages/com.unity.physics@0.3/manual/collision_queries.html
I need to read up on that, first time I hear about it π
This is the unity physics package
I mean things like Physics2D.OverlapBox, Raycast, BoxCast, CapsuleCast, OverlapCircle etc
Thats the first one I got from googling, let me check
is there a guide on that?
It it different from manually placing a collider for each frame(so it matches an animation) then using onColliderEnter/Exit to detect if an enemy was hit?
Is there a guide on what? Doing raycasts and CircleCasts?
This is what u mean
I mean the XXXCast and OverlapXXX methods in this class yes
Right, but just to clarify, if I have a 2d character sprite animation that has a sword animation/whip animation.
Is the query approach going to make it easy to setup those collisions to match the animation?
I am not sure if I am clear on that part or maybe its not even relevant.
Yes because you can use animation events to trigger the queries
I will play with that tomorrow after I setup a scene.
Can I "see" those queries on screen in the editor to make sure they match each animation frame?
For example a sword animation that has a long arc for few frames would hit enemies far from the player for few frames, or if its a forward slash it would hit enemies above player head for few frames before hitting the ground etc
With some pretty simple Debug.DrawLine or Gizmos code you can visualize them
i see, I guess this is still faster that manually adding collider to each frame, so it makes sense to do it this way π
Thanks, I will play around with it and see what I can do!
What is the best way to place objects if they have different sizes?
To what end?
What are you trying to accomplish?
You need to provide some context
!collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
β’ Collaboration & Jobs
Why does nav mesh agent is slow to calculate the path even in the flat ground and almost 40-50 agents! The agents stop and after some duration, they start moving
I'm trying to organize the placement of items on the shelf, left to right and have some space in between! Each shelf will have a different item on it and each item on the shelf will have a different size
it's not like I'm gonna specify for every shelf
the best answer is - know how big the object is and leave enough clearance for it
!collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
β’ Collaboration & Jobs
so objects of different sizes, the shelf will be occupied only by one object, i.e. for example 1 shelf is computers, 2 shelves are laptops, but their sizes are different and the player may want to place them on different shelves.
read the bot message
Yeah I know... my answer was addressing that
ok thanks
have some script that gets the chidren and places them in a row based on a size (set on a component, from sprite or collider for example)
How do you know?
How do I know what?
ive made something that does this in 3d with 3d colliders with custom spacing but i cannot share it
I'm making a 3d game, how do I calculate the distance between colliders?
That's a different question and not really relevant to the shelf question
You mean "how do I know how big the object is?
Define it manually on the object on a script
Or use its Renderer or Collider Bounds
Or use empty child objects to define the extents of it and use their distance.
you can't use the collider?
How i did it was have it configurable what axis is used. i get the collider sizes and add up the total length and add spacing to know the end total length
Then i calculate the start pos and start placing the elements based on their size for the axis and spacing.
both work but colliders are configurable by you more easily
why it's so complicated:(
Thanks guys, your method seemed to work.
Cool, now how to center it all on the center of the shelf.
hows it looking rn?
I don't understand you
show us how it looks in the scene view
snipping tool is your friend
unfortunately I can't show you
how can I center them on the shelf now?
nvm then. if you want to dynamically "center" all the elements you can calculate the total width first then offset by half on the axis
if my placement point starts on the left
Okay, thanks. I'll give it a try.
as i presume the objects you are placing are "center pivot" you need to place them but adjust the position so they get placed with their min edge.
Then when you center them all it will truly be centered.
Is this not valid or something?
In IdentifiableSO.cs:
public abstract class IdentifiableSO : ScriptableObject {
[SerializeField] protected string id;
}
In RunBaseSO.cs:
[CreateAssetMenu(fileName = "Run", menuName = "DeltaD/Run", order = 1)]
public class RunBaseSO : IdentifiableSO { }```
When I create the RunBaseSO from the Create menu I get this error:
> No script asset for RunBaseSO. Check that the definition is in a file of the same name and that it compiles properly.
Can we not have an abstract parent class for SO's? I could have sworn this worked
Ok restarting Unity fixed it. That was weird.
Hello, I have a simple 3d level where a player is on a large cube that rotates on all axis. I want to player to move with the cube, for example if the cube spins, the player is also moving in the game world. Okay so I made the player a child of the cube, easy now the player is not just on the cube not moving, but the player is moving with the cube. One issue now (that I have been trying to fix for a few hours): when the cube roles, so does the player, as in now the player is sideways in the game world, this obv is causing issues with the camera, and it just looks weird from 3rd person.
So my question is how can I keep the player upright at all times relative to the game world, instead of relative to the spinning/rotating cube that it is a child of? While also having the player move with the cube? Any help is appreciated! (fyi I am only a few days into using unity)
can someone help me code movement
!ask π
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #πβfind-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
so u just dont want the player to rotate but keep all of its current functions
yes, which I actually just got working, but now the player camera gets all messed up, as in the controls for the player camera, after the cube rotates
what are the controls for the camera and how is it affected by being a child of this moving cube? is it also rotating?
this is the control for the camera movement:
// Control camera movement
if (cameraCanMove)
{
yaw = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * mouseSensitivity;
if (!invertCamera)
{
pitch -= mouseSensitivity * Input.GetAxis("Mouse Y");
}
else
{
// Inverted Y
pitch += mouseSensitivity * Input.GetAxis("Mouse Y");
}
// Clamp pitch between lookAngle
pitch = Mathf.Clamp(pitch, -maxLookAngle, maxLookAngle);
// Apply the camera's rotation relative to the initial local rotation
transform.localRotation = initialLocalRotation * Quaternion.Euler(0, yaw, 0);
playerCamera.transform.localRotation = Quaternion.Euler(pitch, 0, 0);
}
The parent is the rotating cube. The child of the cube is the firstPersonController (which is where this camera control lives)
huh, just realised that the tooltip attribute works with enums
anyway, im making a generic script for projectiles. what are some methods for finding an object?
so far i've got GameObject.Find and OverlapSphere. my brain is blanking on the rest though 
also added FindGameObjectsWithTag
why does a projectile need to use any Find method? π€
i was thinking for projectiles that follow an object. just trying to account for as many edge-cases as i can (+ i had a projectile that i need to follow an object anyway lol)
but why would the projectile need to manually find that? could whatever is shooting the projectile not just pass the target in?
Seems like bikeshedding
oh good point. i guess that would be more efficient
now i gotta try and figure out how to fit that into my code 
wait nvm, i remember why i was putting that in the projectile script now
a drone enemy i was making also uses the same script. i should probably rename that script 
https://paste.mod.gg/aookhilxzsay/0 for reference, here's the script
A tool for sharing your source code with the world!
i end up rewriting most of this code a lot for a bunch of different things. its way faster for me when i have it in a single component
if i need something more specific then i just rewrite it into its own script
anyway yeah, got a little off topic. anyone know of any other methods of finding a gameobject?
I am having some trouble understand the workflow and architecture of engine. I come from a background in Roblox Studio and a common setup is a microservice architecture with a bunch of small systems coupled together that call each other. Rather then a bunch of scripts within the objects themselves
what the qustion is?
i assume their asking about how they should set-up their projects. how the code should be put together and all that.
if you're new to unity it may be a good idea to check !learn first
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
Might also be helpful to forget everything about Roblox, Unreal, Godot, Processing, Enterprise code and web dev for a while when learning a new framework like Unity
https://docs.unity3d.com/6000.0/Documentation/Manual/working-with-gameobjects.html
This explains the basic ideas of GameObjects and Components
thanks
I remember talking recently with someone about how Roblox games are "shaped". It did feel pretty alien to someone used to Unity.
Yah its much different
Genuine question. I believe this is a c# or i'm crazy. Why does: float a = (int a/int b) Return a as zero?
There was a bug in my code with this and this drove me nuts until i saw this on the debugger
it actually returns an error 
wait no it doesn't
guh, need more coffee
C# needs some milk bro.
real 
I'm gen upset tho this was 2 hours of debugging
hm, maybe its something else. i can try helping if you send the full script
this should work just fine
that code won't compile
public bool ReduceHealth(int Damage ) {
health -= Damage;
float precentage = health / FullHealthRef;
this.SetSpritePrecentage(precentage);
if (health < 0)
{
return false;
}
else { return true; }
}``` legit just this.
heath is a pub var
you're doing integer division
since they're both ints
print their values
if health is less than FullHealthRef it will be 0
.e.g
5 / 10 is 0 with a remainder of 5
when doing integer division
But does not any other language convert it?? I swear I'm not crazy
Most languages will give you 0 here
especially when the equated var is a float
wait really? i've never noticed that before
something like python or JS might give you .5
The / operator has no idea what its result is being assigned to
it only see two integers as inputs
and does integer division
This drove me nuts for 2 hours because I though C# would understand this.
it understands fine
when you do int / int it does integer division
If you want a floating point result you should cast one or both operands to float first
huh, yeah you're right. i'll have to keep that in mind for the future
you need to cast at least one of those ints to float so it auto performs floating-point division
Don't end up like me kids
Wait can I dead ass just do this? float a = (float) b/c
Brother 
Sobbing crying. Dying a little inside.
4 years of comp engi has lead me to this moment of never actually experiencing this.
Ya know maybe I haven't coded enough in my life.
i've been doing coding in c# since i joined this server. but, i still make basic errors like that.
seems like no matter how hard you try and prepare, it's pretty much impossible to be able know the answer to every problem. just gotta learn as you go
ya know the more I think about it. The more i realize this is the most (Making a game in unity) I've ever utilized floats. I've worked with a lot of whole numbers in code.
That or i'm just using a library someone created or bytes or a network/Dis Sys protocol.
ive made that mistake so many times and still do but im only now starting to catch it faster
ive spent many hours
Rider will warn you if you're assigning integer division to a float
That's a syntax error.
Btw, how does Unity expect us to prepare to migrate to Unity 7 when it comes?
Will the code be mostly transferrable as long as they're not depriciated?
Nobody knows anything about Unity 7 basically, including whether it will be called Unity 7.
Reasonable.
if you are referring to the .net modernization, the advice for that is to stick to .net standard for the api compatibility level rather than .net framework
That's usually the case. There's no single version that can't be converted between with some adjustments.
Especially knowing that unity is very picky about backwards compatibility
Unity 7 isn't a normal release. Whisperings have it having a massive amount of variance regarding changes and impact
Depends on what they've settled on now they've gone through the change of management and had time to reflect
I've heard talk of ripping out legacy systems completely; but also that management was trying to scale back plans. Nobody can say anything with any confidence beyond the announcement threads made last Unite
I mean, if you're homeless, just buy a house if you use legacy systems, just don't use them.
Unity could use some cleanup. Too many solutions to one problem
Hi guys, I have purchased an asset from the store. It is a UI asset. They are using an OFL licensed font in it but it's not looking good for me. Can I change the font when I'm using the asset in my game? Its license agreement says "Standard Unity Asset Store EULA".
You can modify assets however you'd like
I'd post that onto a paste site even though I'm not likely able to help you here. My only suggestion is chopping it up and printing the work to some doc with a timestamp to figure out what parts of it could be optimized upon.
Thank you!
how would i give my plane lift? and make it turn? i cant find any proper tutorials, the only one i found has no lift. also tried to do it myself, but turning is very unstable
Maybe show your code and explain a bit more, what you are trying to do.
a airplane, i can give code example later. i just need a example of how to do the code, not the code itself
afair i got a baseplate and a model(i made) as a plane
How realistic are we talking?
Because I'm not an aerodynamics expert... but for lift you could just use AddForce/AddRelativeForce, right
And turning can be done with torque
A joint (probably configurablejoint) can be used too but can give pretty wonky results if you don't adjust it properly
i am trying to figure out which public fields are updated and when on GameObjects but is very inconsistent, sometimes when I hit save after adding a field it doesnt show and other times after removing the field it never leaves
for example I removed a boolean from my script and it's still in the explorer
As soon, as your scripts get "reloaded", it should show you the correct inspector. If not, you might have turned off reloading after saving a file
maybe, would hot reloading mess with that?
with "hot reloading" you mean the Unity one?
I have Fast Script Reload by Chris Handzilk
yeh, I dont know this one, but I guess, it might
is there an official unity one?
Unity should reload your scripts on default, when you change them. your plugin is for playmode bneing active and main changes, so it does only reload the parts and not entire classes and break your playmode session
is there a way to reenable reloading after saving?
But description already says: β’ Creating new public methods
Hot-reload for new methods will only work with private methods (only called by changed code)
ahh
So, when you enter or leave playmode and did not turn it off, unity should recompile anyways
but if you rely on hotreload in playmode (feels hacky to me :D), you should read about what to expect from it
it doesnt seem to be working at all now even after restarting
Just made a boolean in the script, saved, entered unity and hit play but it doesnt appear
Remove the package and see what happens
Probably when CoreCLR replaces Mono (hopefully in Unity 7)
Script reloading will become a thing then, which is essentially Hot reloading as far as I know
ok now my unity is fully busted
restarted unity entirely and its not synching code at all
Check that your IDE is correctly installed
it is
well
it was working before I installed the package
so not sure how that works
it's very inconsistent
so did you remove the package?
https://pastebin.com/HPePvkJj grab script
https://pastebin.com/UFaeAgpD lever script
https://pastebin.com/aeE4Gcf0 trapdoor script
the balance script I didnt include just have rigidbody2D.Moverotation()
problem is when I grab to pull the lever, its like changing its limits the second time I grab.It cant get past a point by grabbing but can push it with my body.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
yes
and then restarted unity and visual studio
it was working and every other time it breaks
like the code has an error right now and yet unity runs as if it doesnt
as well as not creating the explorer value
explorer => inspector ?
Maybe restart your entire system. that package seemed to hook into a lot of stuff
Starting by deleting the library folder. Maybe regenerate the csproject files from settings menu
where can I find that fodler
Right to your assets folder in (actually) explorer/finder
alright trying it out
still nothing
this alone makes me want to move to godot lmao
ok so the only times the files sync
is on
- Startup of unity
- when I hit "attach to unity" in visual studio
maybe remove vs and reinstall it !ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
β’
Visual Studio (Installed via Unity Hub)
β’
Visual Studio (Installed manually)
β’
VS Code
β’
JetBrains Rider
β’ :question: Other/None
Is burst supported in webgl i mean can i run my jobs in webgl ?
Burst is supported. Jobs are supported, but they don't run on separate threads.
if i use paraleljobs in webgl they behave in single thread and other platfroms its uses other threads too right ?
Yes
webgl is single threaded
for secruity reasons
you can actually enable those native arrays shared buffer arrays but most services dont support them. (Actually they been long since depreciated)
thanks alot @latent latch @late lion
WebGPU supports compute shader surprisingly enough so can take advantage of that
odd time to be alive when there's more GPU support for browsers
in this code the running anim works well it switches to the walk animation but the player is unable to move like it glitches out after 1 or 2 key presses and I want it to switch to the 2nd frame of the walk animation in the blend tree
https://paste.ofcode.org/b7sUm2sgjL77HmjY3Udq2z
very simple, 2 inputs by gyro
i tried giving lift based on speed, and the plane did go up, but turning was a nightmare
i have no idea how to combine lift and turning
if we dont see your code, we cant find out what you might be doing wrong. Also your description does not help "was a nightmare" <= why?
i cant post code atm, i will be able in ~45min. will ping when ready
Just post, please dont ping π
Quick question. Say I have to NPCs with CircleCollider2D and Rigidbody2D, and they are supposed to detect each other. Both colliders have a radius of 5. Does the colliders detect the rigidbody of the other NPC, or will it detect their circle collider, effectively making the radius needed be 10?
Can i use native list like this ? for extracting data inside a job because i dont know the possiable lenght of result
[NativeDisableParallelForRestriction][WriteOnly] public NativeList<NetworkTileBurstData> Results;
if i dont use disable tag it gives error for reading it i guess, should i use it anyway π
jobs are designed to operate on immutable buffers, typically arrays, so list usage or any other "advanced" data structure is dangerous or has a lot of sync-overhead, negating the benefits of job-style parallelization.
depends what layers are detecting what layers
@cold parrot so if we dont know the lenght of the outcome inside job should we use arrays like a fixed buffer and give them a extra size for not reaching limit then discarding the empty or invalid ones inside buffer is this the best route ?
NativeList has a parallel writer for this purpose.
https://docs.unity3d.com/Packages/com.unity.collections@2.5/api/Unity.Collections.NativeList-1.ParallelWriter.html
your problem is not efficiently solvable by jobs if you don't know ahead of time how big your buffers are, as one solution you can just allocate buffers that are large enough to hold the max-length you typically expect
if you use parallel writers as suggested you will need to pay the synchronization overhead
But note, parallel writer cannot resize the internal array, so you will have to have pre-allocate for the maximum size.
@late lion @cold parrot thanks a lot i will give a try for both methods
NativeList<NetworkTileBurstData> results = new(allCombinations.Count,Allocator.TempJob);
[WriteOnly] public NativeList<NetworkTileBurstData> Results;
public void Execute(int index)
{
NativeList<NetworkTileBurstData>.ParallelWriter writer = Results.AsParallelWriter();
writer.AddNoResize(new NetworkTileBurstData());
}
Still getting old issue also i used parallelwrite for it , i cant find what i am missing :/
InvalidOperationException: SolveCombinationJob.Results is not declared [ReadOnly] in a IJobParallelFor job. The container does not support parallel writing. Please use a more suitable container type.
Also do can give a advices for nested lists for example if i want to NativeList<NativeList<NetworkTileBurstData>> its not possiable therefor what should i use for it UnsafeList ?
You are supposed to create the parallel writer outside the job and pass it in.
[WriteOnly] public NativeList<NetworkTileBurstData>.ParallelWriter Results;
You can have a NativeList<UnsafeList> if you must. It's not a very cache friendly data structure, though. It's better to have one big array with each "list" back-to-back with enough items for each one already pre-allocated.
NativeParallelMultiHashMap i will searched and these can help me i guess
the order not important for me
thanks a lot let me try that
Colliders dont usually detect rigidbodies, they detect other colliders (which in some cases, might also have a rigidbody attached), although you shouldnt need to double your radius for this detection to happen, a collision is detected on the frame that any "pixel" of the either collider overlap eachother, and OnCollisionEnter2D or OnTriggerEnter2D will be fired in the same frame - so from what you described, your collision should detect the circle collider on your other NPC, and as Mao mentioned there could be exceptions to this, such as your NPCs (or more specifically, the object with the collider) being on different layers
How can I make a circle collider but in 3d? Like with depth
for example for a circle table
You mean a cylinder ?
There is no primitive cylinder collider, but you can use a convex mesh collider
mm... im trying to use the cillynder but it doesnt work, i need something like a round table and you cannot get that with cyllliner
yes, because the cylinder object uses a capsule collider
I was asking to confirm the shape, I don't remember of a cylinder collider
If you remove its capsule collider component and add a mesh collider component, you'll get the right shape
you should also tick the "Convex" box
since this is, indeed, a convex shape -- it has no holes or valleys
i put a mesh collider, tick convex and nothing happens, i cant even previsualize the green lines of the collider
Show the inspector for this object.
where mesh π
No mesh assigned
we all expected it π
ah, I thought you were using a Cylinder object here
Meshn't
which would have a mesh filter component that holds the cylinder mesh
its a particle system, it doesnt have any mesh and anyway even if i apply a mesh it doesnt appear the green lines
that would've automatically filled in the mesh collider
The easiest thing to do, to be honest, would be to just slap a cylinder object on as a child
It actually has a capsule collider lol
That'll give you something you can see
The idea was to remove that capsule collider and put on a mesh collider
do dictionaries not appear in the inspector?
It'll grab the mesh from the MeshFilter component automatically
No. Unity can't serialize them.
I often just serialize key-value pairs and then fill in the dictionary at runtime
Oh yeah oops i misread mesh filter as mesh collider
like an array of key value pairs?
MeshCollider cant be manipulated right? once it acquires the form of the object is like that forever? And what does convex do
That or a list/array of keys and another one for values
You can also customize the serialization to make your dictionnary serialized as 2 list (keys and values) and make your custom inspector to render it
KeyValuePair can't be serialized so if you go with a single list/array you need to use a serializable type to hold the key and value
all components have doc pages, you can go read it to learn what things to π
https://docs.unity3d.com/6000.0/Documentation/Manual/script-serialization-custom-serialization.html (page on custom serialization)
Yes, although you can scale the object to change its size, at least
"Convex" causes it to operate differently.
Normally, a mesh collider can represent any mesh shape. It's kind of like a thin shell.
When you turn on "Convex", it bakes a collider that is solid -- it's kind of like stretching plastic wrap over the mesh
now I got it, the only "problem" is that the collider has to be a child as u said, btw this collider also affects if something drops from above? Or just the walls?
This gives you better behavior. The collider actually knows what's inside and outside.
As long as the mesh has a top and bottom, it'll work
(actually, even if it didn't, the convex baking process would still wind up giving you a top and bottom)
yeah, it was a cylinder which i scaled down so it had, just removed both of these
The most flexible option would be to generate a mesh with the exact size you want and manually bake it. But that sounds a little excessive
Yeah -- the Mesh Renderer is obviously not needed
and the Mesh Filter only really needs to be there for the Mesh Renderer to use.
The Mesh Collider does grab a mesh from the Mesh Filter when it's added, but it doesn't rely on the Mesh Filter being there
okay, thanks a lot β€οΈ
!collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
β’ Collaboration & Jobs
Hey what's up y'all
I have this
And I get a stack overflow, as I assumed
I'm trying to fix it but don't really see a logical thing to do here.
Well, you should try using a private field instead of doing LockMouse = value. You have quite a big circle here
To put it simply, you have a method that calls itself
someone warned me when i said hi
I figured it was recursive but what exactly do you mean by using a private field? In what way?
@hoary root You did read the warning message right?
now i see but i got kicked joined back and then got warned
i didnt say anything after i got kicked
I meant this
private bool lockMouse;
public bool LockMouse
{
get => this.lockMouse;
set
{
if (this.lockMouse != value)
{
this.lockMouse = value;
}
}
}
this is obviously optional, but i wanted to make the difference between the field and the property more visible
I see, but how does that change anything? I don't really understand why it should.
@hoary root Read the warning message, remove pronouns trolling, read #πβcode-of-conduct and don't spam unrelated channels.
The difference is that your setter will assign the value to the field instead of calling the setter again
By the way, in here lockMouse (notice the lowercase) and LockMouse are a typo or are they supposed to be capitalised like that?
Oh nevermind
I understand it
the movement now works but now the animation freezes even when the z key is released and it stays in the run blend tree without switching to the walk one and the freezing animations are now also staying for longer like one state is being repeated for 3 keys or so script - https://paste.ofcode.org/Ftdf37bDpS8fGPqRz2VNDZ pls help fix it
Setting Animator.speed to 0 will freeze the transitions also
I pointed this out to you before
Is it generally a good idea to set timescale to 0, to allow for pausing?
Time.timeScale = CurrentPlayMode == PlayMode.Play ? 1f : 0f;```
then what should I use?
You can control an animation state's speed or time directly if you need to
pls can you guide me on how to?
I know timescale generally only helps to stop the games time from increasing, so any actual logic in my various C# files will continue to run even when the game is in this fake paused mode
but the problem is that I have other npcs and can't have them pause
this is very common, yes.
you will need to separately handle any logic that doesn't depend on game time that also needs to be paused
https://docs.unity3d.com/Manual/class-State.html
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/AnimationState.html
You'd want to look at either the speed or time property
dont mind my posts, it seems we're both trying to solve relatively the same problem at the same time!
ok understood π
great minds think alike π
there is something called motion time here
Yes that's AnimationState.time in C# (or normalizedTime idk)
The second link is for the script documentation
@hexed pecan tried this but the run animation isn't being played and the walk animation is extended from 4 frames to about 6 to 7 frames https://paste.ofcode.org/LSGKYjku8sq7bhGyXJWUy5
Hello, i would like have a float value but no with the "E" something to readable for human ex : "0.0789" not that : "-8,109922E-12"
e is scientific notation
https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
Depends on the size of your numbers, but probably:
Debug.LogError($"DIFFERENT {number1:F3} {number2:F3}");
