#archived-code-general
1 messages ยท Page 12 of 1
just a remind the ammount of data you can save to playerprefs is very limited
so saving images in there not the best idea
really? could u link me a source
any idea what i should be using? because i was thinking of users saving multiple images in the app
it depends on the platform you are targeting windows has a limited size that can be stored to the regestry (that where the playerprefs end up on windows)
from some forum / unity answer posts people tested that andorid will crash after some none specifyed size and webgl has a hard limit of 1mb
the better way is to store data in the Application.persistentDataPath
https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
thanks for reminding, yeah i checked documents and it said it has a limit of 1mb for playerprefs, that's not really a good idea for the app that im building ๐ฆ
Sounds like you described exactly how to do it yourself
thanks so much for bringing me to this direction, i feel like this is the right way indeed
its stored in %userprofile%\AppData\Local\ on windows, i dontnthink its limited
also its the same directory in windows as Application.persistentDirectory
"Windows: HKCU\Software\ExampleCompanyName\ExampleProductName"
either this is correct or the documentation needs updating
idk why they used separate configurations for windows apps and windows store apps, i dont even know what the second type is
I am going to use a toggle group : my question is is there a way to give it a method when I pick one of the toggles? OR do I have to define each toggle's on changed value method?
each one separately, preferably through script
quick question,
Code objects means the instances of the classes of a script?
Something like
Vector3 vec = new Vector3(var x, var y, var z)
```from the Vector class would create a new vector instance
GameObject is every entity on a scene?
They probably mean a C# object yes
ah thanks man
oh yea I checked, all gameobjects on a scene are the instances of the gameobject class
correct me if I'm wrong
whoops my mistake, thanks for correcting
gotcha thanks
aaaaaah thank you
and a tip, use delegates to persist local variables
no need to I just want to edit a bool ๐ but thank you
anyone knows the location of UnityEngine.XR.Interaction.Toolkit dll ? im trying to reference it in my library
How do those [expunged] quaternions work? T_T I got code:
arrowV.localRotation = vertDir == EThirdDir.Down ? quaternion.Euler(0,60,150) : quaternion.Euler(0,56,-42);
that setups the child's rotation, but it instead sets the rotation to (-180, 17.7469, 134.367) or (0, -31.436, 113.557). Neither is what I put into the function that I expected to exist specifically to spare developers from the horrors of quaternions...
Wow I didn't consider the fact that I don't need to get an actual limited plane and instead a virtual endless plane would give the same result, lol
Every day is a new day to learn that I'm dumb xd
u sure what ur seeing is localRotaion and not global?
The parent's transforms are all 0's
youre setting local rotations, and what u see on inspector are world rotations
I know, but parent has no rotation so child should have no rotation to add to its own, especially inside a prefab edit window.
nope parents having no rotation has nothing to do with child rotations
The one you see from inspector is local rotation
ops
If you debug.log arrowV.localRotation.eulerAngles after that line, they surely are something like the Quaternion.Euler you set them too.
Also, quaternion lower case is the math library one, Quaternion big case is the rotational one. Not sure if that's your problem or it's just a typo.
Also, just setting them this way is not better or worse then just setting the EulerAngles. Doing math with rotations should always be done with Quaternions, otherwise you run the risk of Gimbal Locks, but just setting it doesn't matter either way.
But yeah, reading the docs, I think you use the quaternion.Euler lower case variant. That rotates differently then the big one.
Not sure if that's your problem or it's just a typo.
It was totally the problem, thanks!

That rotates differently then the big one.
I just... why would anybody set those functions like that...
Euler(Single, Single, Single, RotationOrder)
Returns a quaternion constructed by first performing 3 rotations around the principal axes in a given order. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin. When the rotation order is known at compile time, it is recommended for performance reasons to use specific Euler rotation constructors such as EulerZXY(...).
At least 1 of the problems is that this one is in Radians. Not sure if the axis order is also different. Anyhow, the math libraryquaternionone is only useful for DOTS I think, never used it in MonoBehaviour Unity variant. DOTS need speed, so I think something along those lines they are different, but that's just guessing from me, or maybe it's managed vs unmanaged.
Anyone here familiar with Photon PUN? If so I am having a problem where OnRoomListUpdate() is never called even after someone creates a new room (and the lobby is joined beforehand) . Any help would be appreciated.
Probably because Unity mathematics library is to match with hlsl mathematics which likely to use radian
Photon has own discord and PUN is not recommended anymore
Thanks for letting me know, ill check out their discord.
Is it possible to have functions in a loop somehow? Like i have an array that i want to loop through and then have and if statement. But since 3 all overlap and are all true i need to have some function.
Can you show your current code? Because I don't understand what you are trying to ask.
can i try to explain in dm? and show code there to not clutter the channel
No, just do it here, the #854851968446365696 at the bottom shows how to post code.
okayy
so i have an array that takes values out of another array and counts how many values are repeated. The values from the first array are randomly generated numbers from 1 to 6.
there are 5 random numbers in the array total
so any time i want to use the numbers from the array that counts the repeated for an if statement id have to do if NumberArray[0] && NumberArray[1] ... and so on
so i made a for loop
that looks like this
{```
i put the if statements in there
if [NumberArray[i] {
so for a while now noone was able to solve that, could someone take a look and try to think of any solution? ive been checking code over and over again and the only solution i see is to somehow change time.deltatime on the second script, tho every attempt of mine to do so failed
link to my original message in #๐ปโcode-beginner #๐ปโcode-beginner message
more info and my screen records are in the thread
id be very thankful if someone could help lmao
for(int i = 0; i < 6; i++)
{
if [NumberArray[i] {
Please post it this way, it's way easier to read.
okayy
cs on the same line as the backticks
Anyhow,
if [NumberArray[i] {
Doesn't make much sense.
But maybe you weren't done yet.
Can you briefly explain:
- The expected behavior
- The current behavior
the design making obstacles appear based on time is bad imo, instead spawn obstacles based on distance
its all in the attached thread, but basically the first pipe after the powerup spawns apparently in random places, its offset from where i would want it to be. it sometimes can appear closer or further from the last pipe generated from powerup. you can see that behaviour on screen recordings in the thread too
its my very first real project, do you suppose that changing the said thing would resolve the issue?
200%
yea i suppose that would definitely make sense. could you roughly tell me how can i do that?
make a list, check if the farthest obstacle shorter than a definite distance, if yes spawn new on at x offset
oh and i suggest you move the player and not the obstacles
i figured it would be much easier to move the pipes instead, pretty sure original floppy bird is based on that design
tho thanks, ill definitely try to use that
sorry im back had to do something real quick
they did it the hard way but sure
ok so
NumberArray is the name of array that counts the repeating randomly generated numbers from the first array
this is what i used for the for loop
inside i then had an if statement
but like i explained
if (NumberArray[i] == 2) {
and
if (NumberArray[i] == 3) {
overlap
if (NumberArray[i] == 2 && NumberArray[i] == 3) {
or the other way around
im not quite sure how to explain
this is way too hardcoded
use a for loop
to go through the numbers
and check if they're equal however you want
i am using a for loop
this
Any idea why calling GetValidProperties causes stack overflow?
private static IEnumerable<PropertyInfo> _except;
private static IEnumerable<PropertyInfo> Except => _except ??= GetExcept();
private static IEnumerable<PropertyInfo> GetExcept()
{
foreach (var propertyInfo in GetValidProperties(typeof(SystemBase)))
{
yield return propertyInfo;
}
}
public static IEnumerable<PropertyInfo> GetValidProperties(Type type)
{
foreach (var propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public).Except(Except))
{
if (propertyInfo.CanRead) yield return propertyInfo;
}
}
GetValidProperties() calls Except. Except calls GetExcept(). GetExcept() calls GetValidProperties()
infinite recursion
oh yeah
I just realised
damn
bruh, inherited properties aren't the same as properties on base types
hmmm
is there a way to get the navmesh system to work on a sphere? If I add a navmesh surface to a sphere normally, it just covers the top and not it's entire surface. I have zero experience with Unity's navmesh, so I may be missing something obvious
just add to a dictionary Dictionary<int, int> where the key is the number and then increment the value (which is how many there is of that number)
I doubt it. You'll probably need to implement your own pathfinding on a sphere.
Is there some other tool that would work on spheres? I don't have the coding knowledge to implement that myself
private void Tally()
{
var tally = new dictionary<int, int>();
for(int i = 0; i < NumberArray.length; i++)
{
var number = NumberArray[i];
if(tally.TryGetValue(number, out var tallyValue))
{
//I think you can do that, otherwise you'll need to set it back to the dictionary
tallyValue++;
}
else
{
tally[number] = 1;
}
}
}
you have to set it back
ah, i always forget
private void Tally()
{
var tally = new dictionary<int, int>();
for(int i = 0; i < NumberArray.length; i++)
{
var number = NumberArray[i];
if(tally.TryGetValue(number, out var tallyValue))
{
tally[number] = tallyValue++;
}
else
{
tally[number] = 1;
}
}
}
I'd do this somewhat simpler way:
int currVal = tally.GetValueOrDefault(number);
tally[number] = currVal + 1;```
true
anyone know how i can fix unity using visual studio instead of vscode whenever i restart the project
Edit > preferences > external tools, then there should be a drop-down at the top
hmm.
So when I create Delegate from PropertyGetter, can I cast it to Action<object> type?
Assuming Property is not object type
I'm talking about this as example
var kek = propertyProvider.GetType().GetProperty("Kek", BindingFlags.Instance | BindingFlags.Public)
.GetGetMethod().CreateDelegate();
If it's a getter then wouldn't it be Func<object> not Action<object>
๐ค
sooo, not really
damn
I need to convert unknown Property Getter to delegate or maybe some other semi-fast alternative
Is the return type value type?
Value type return is not compatible with Func<object>
You may just make a lambda that calls PropertyInfo.GetValue
Or do Delegate.DynamicInvoke , both are slow
DynamicInvoke is slow ๐
what delegate type would be for value types?
The exact Func<T> type
๐ฅฒ
Make your method return object ๐
that's the point though
I'm doing anti boilerplate work
where I want to return any type, because it'll use ToString anyway
Then make a Func<T> then make a wrapper Func<string> that calls ToString on it
Do MakeGenericType
where can I find this one?
From typeof(Func<>)
can sum1 help me fix thsi code?
๐ ๐ฅ
do u have complimentary sunglasses b4 i help?
damn, I think this won't be compatible with il2cpp
too much reflection ๐
all right, I guess propertyInfo it is
Yeah it won't work for IL2CPP if it's stripped out
Your properties can be stripped out too FYI
nah, it's more about JIT which involves creating generic types
anyways, I don't have control over stripping of my properties either
If you use Func<int> somewhere in code you can make that type
which is kinda sad
well, it's meant to be generic in this regard, so not an option
I hope PropertyInfo.GetValue is fine with Il2cpp
So far this works
var property = typeof(MainMenuPresentation).GetProperty(nameof(MainMenuPresentation.Lul),
BindingFlags.Instance | BindingFlags.Public);
var result = property.GetValue(new MainMenuPresentation());
in editor at least
Yeah had to go home and make dinner.
But still, this doesn't make much sense. This line can never be true. NumberArray[i] can't be 2 and 3 at the same time.
It seems you simply want to count duplicates, and there are a bunch of examples of that online for C#. So I don't know what to do with this question.
If you don't use Lul and it's not preserved it could be stripped out
but I'm annoyed to make a build, cause due to some new version of WASL, building little webGL apps takes literally 30 mins
Minimal is fine
it doesn't use user code
its all good i got it working anyway. Im TERRIBLE at explaining so i guess it makes no sense bcs i didnt explain it well.
Thanks for trying to help!
Sure that's fine
Hello im trying to implement portals using brackeys smooth portal video but it looks like his PortalCamera script is outdated and isn't working as intended.
using UnityEngine;
namespace DefaultNamespace
{
public class PortalCamera : MonoBehaviour
{
public Transform playerCamera;
public Transform portal;
public Transform portal2;
void LateUpdate() {
Vector3 playerOffsetFromPortal = playerCamera.position - portal2.position;
transform.position = portal.position + playerOffsetFromPortal;
float angularDifferenceBetweenPortalRotations = Quaternion.Angle(portal.rotation, portal2.rotation);
Quaternion portalRotationalDifference = Quaternion.AngleAxis(angularDifferenceBetweenPortalRotations, Vector3.up);
Vector3 newCameraDirection = portalRotationalDifference * playerCamera.forward;
transform.rotation = Quaternion.LookRotation(newCameraDirection, Vector3.up);
}
}
}
Using this script right now makes the portal camera erratic and i not experienced enough to know how to fix it.
Can you show/explain what you mean by erratic? Rotational problem? Visual problem? Positional problem?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test_hover : MonoBehaviour
{
Rigidbody hb;
public float mult;
public float moveForce;
public float turnTorque;
void Start()
{
hb = GetComponent<Rigidbody>();
}
public Transform[] anchors = new Transform[4];
public RaycastHit[] hits = new RaycastHit[4];
void FixedUpdate()
{
hb.AddForce(Input.GetAxis("Vertical") * moveForce * transform.forward);
hb.AddTorque(Input.GetAxis("Horizontal") * turnTorque * transform.up);
for (int i = 0; i < 4; i++)
ApplyF(anchors[i], hits[i]);
}
void Update()
{
}
void ApplyF(Transform anchor, RaycastHit hit)
{
if (Physics.Raycast(anchor.position, -anchor.up, out hit))
{
float force = 0;
force = Mathf.Abs(1 / (hit.point.y - anchor.position.y));
hb.AddForceAtPosition(transform.up * force * mult, anchor.position, ForceMode.Acceleration);
}
}
}
I am trying a hoverboard script but for some reason it doesnt move when I try to
Could someone help
i think its both a rotational and positional problem
values going crazy until it says infinity lol
Can you show a screenshot of that? Because this code should not reach infinity at all.
I have a feeling the problem is not this script. This all seems valid code.
You can disable this one, and run the game again, it's should still freak out.
Hmm, you are moving PlayerView, which is under Player it seems. Are you sure that's correct from the tutorial?
Have you tried disabling compression?
is it related to wasl?
it gets really stuck on linking phase
I barely have any assets anyway
only uxml practically
No, but it speeds up your WebGL builds. In the past it shaved 15 minutes off a build for me. That was an older version though, perhaps 2020.
nah, don't think it's related
well that is the player camera
its how he does it
Went from 20 to 5 minutes
older wasl version made builds in just 5 mins yeah
Fair enough.
Ah you're using toolkit at runtime? I heard it wasn't ready.
I know it's possible, I thought maybe it wasn't quite good though to rely on. I'm looking forward to the workflow when it's feature complete.
I never used uGUI, only UI Toolkit
and I like it
it's very close to web ui, so I just use the same good practices
Awesome. Nothing good in UGUI.
it's also cool that it's written in UXML, which is very similiar to XAML used in many .net UI solutions
Yeah I'm a web dev too. I have been wishing for html in unity for years.
Okay, well the setup is strange.
You have the PortalCamera script on the camera from the portal.
And you do:
transform.position = portal.position + playerOffsetFromPortal;
Which positions the camera to the camera + playerOffsetFromPortal, teleporting the thing further.
And I feel you do this on all camera's. Teleporting the whole scene to infinity.
transform.position and portal.position is the same if you did not catch that.
I'm no web dev though ๐
It's still a superior system
Even if you don't know it
Provided it doesn't have terrible issues, which is my fear haha
well anyways, I literally wrote desktop application using UI Toolkit and it worked better than Microsoft's MAUI version ๐คฃ
40 mb ram with Unity vs 70 mb ram on MAUI
no its only that camera that is going crazy distances
I'm not familiar with MAUI. Is that native windows UI?
no, it's their very new UI solution which is meant to be multiplatform
But if your camera goes 1000 meters forward, and it still sees the same thing? What happened then?
The whole portal system teleports with you
Ahh I get what you mean now. The only thing is the camera teleporting away, not the portal mesh itself.
But the cause is still the same.
Your portal is the same as transform in your script.
transform.position = portal.position + playerOffsetFromPortal;
So you always add playerOffsetFromPortal to the position, every frame.
Okay, I just don't understand why you want to move the portal camera's at all. Aren't they supposed to be used for the rendertexture of the plane?
This wasn't in Brackeys tutorial as far as I can remember.
i think i misunderstood the video and what he put in the transform variables
else if (NumberArray[0] == 2 && NumberArray[1] == 2 ||
NumberArray[1] == 2 && NumberArray[2] == 2 ||
NumberArray[2] == 2 && NumberArray[3] == 2 ||
NumberArray[3] == 2 && NumberArray[4] == 2 ||
NumberArray[4] == 2 && NumberArray[5] == 2 ||
NumberArray[0] == 2 && NumberArray[5] == 2 ||
NumberArray[1] == 2 && NumberArray[4] == 2 ||
NumberArray[0] == 2 && NumberArray[2] == 2 ||
NumberArray[1] == 2 && NumberArray[3] == 2 ||
NumberArray[3] == 2 && NumberArray[5] == 2 ||
NumberArray[2] == 2 && NumberArray[4] == 2 ||
NumberArray[0] == 2 && NumberArray[4] == 2 ||
NumberArray[1] == 2 && NumberArray[5] == 2 ||
NumberArray[0] == 2 && NumberArray[3] == 2 ||
NumberArray[2] == 2 && NumberArray[5] == 2
) {
would this cause any problems like lag? i know it can be done more efficiently i just couldnt figure out how. it works like this. But does this cause problems? Its in a for loop.
Terrible code, but by itself should not cause lag if you only do it 5 times per frame I think you said.
Also depending on how many thousands of else if's you programmed. But with an array of 5 it should all work.
This won't scale at all though.
no this is the only way i have like this. the other ones are WAY more efficient.
also don't crosspost
im basically checking pairs in a dice game of 5 dice. But i wanted to do 2 pairs of the same 2 numbers.
you already asked in #๐ปโcode-beginner
#854851968446365696 and #๐โcode-of-conduct are a good read for new joiners of the server
Wtf I just answered this in #๐ปโcode-beginner
a reason why crossposting is in the rules ๐
Fyi writing code like this is actually as or more efficient than using a loop. But not in any way that matters. It's just terrible to read and write.
Yeah sorry just deleted it from -advanced since i also posted it there T.T
Lol
Ahh okayy
I love the idea that this is advanced code
The problem with your code is not efficiency
i know its not just wanted to make sure people saw it since ive been confused for like 3 hours
This server has tens of thousands of users, it will be seen
Okay! thanks for the help again โค๏ธ
_layerMask = 1 << LayerMask.NameToLayer("Default");
_layerMask = ~_layerMask;
what does ~ mean
https://help.vertx.xyz/programming/physics/bitmasks it inverts the bits
oh so the first line is "detect default layer" and the second line makes it "detect everything except default layer" ?
Yeah
You can also use LayerMask.GetMask instead of shift operator
oh is that new
I don't think so?
Hey! Wondered if there was a dynamic way to instance a custom object from assets? I'm trying to spawn this from code:
https://assetstore.unity.com/packages/tools/particles-effects/v-light-volumetric-lights-2037
So far I've created it through editor: GameObject --> Create Other --> (V-Light type). However it doesn't seem possible to add it to prefabs for some reason, only scenes. So now I want to instance it at runtime from script. Any idea where to start?
oh shit i didnโt think it actually did anything i just thought you used that when you had two variables you needed to name the same
huh? can you give an example?
oh were you just looking at var1 = ~var1?
Hope it's ok to bump this. Any ideas?
hi
anyone can review why this not working?
using UnityEngine;
using UnityEditor;
public class PlayerSpawnerMethod : EditorWindow
{
private GameObject playerSpawnerPrefab;
private GameObject[] spawnPoints;
[MenuItem("Window/Player Spawner")]
public static void ShowWindow()
{
GetWindow<PlayerSpawnerMethod>();
}
private void OnGUI()
{
playerSpawnerPrefab = EditorGUILayout.ObjectField("Player Spawner Prefab:", playerSpawnerPrefab, typeof(GameObject), false) as GameObject;
spawnPoints = EditorGUILayout.ObjectField("Spawn Points:", spawnPoints, typeof(GameObject), true, null) as GameObject[]; <-- ERROR
if (GUILayout.Button("Create Player Spawner"))
{
if (playerSpawnerPrefab == null)
{
EditorUtility.DisplayDialog("Error", "Please select a Player Spawner prefab", "OK");
return;
}
GameObject playerSpawner = Instantiate(playerSpawnerPrefab);
playerSpawner.GetComponent<PlayerSpawner>().spawnPoints = spawnPoints;
Vector3 mousePosition = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition).origin;
playerSpawner.transform.position = mousePosition;
Selection.activeGameObject = playerSpawner;
}
}
}
the args is incorrect by view of vs studio
every one of those red squiggles has a whole error message you should be reading
read your error messages
i tried fix but i stuck in convert GameObject[] to GameObject
because that doesn't make sense
If you want to show an array use https://docs.unity3d.com/ScriptReference/EditorGUI.PropertyField.html
GameObject[] is a collection it contains 0 or many gameobjects
public class Tetris : MonoBehaviour
{
PlayerMovement playerMovementScript;
PickUpController pickUpControllerScript;
public Camera camera;
public GameObject startMenu;
public GameObject allUi;
private bool gameOn = false;
private void Awake()
{
playerMovementScript = GameObject.FindObjectOfType<PlayerMovement>();
pickUpControllerScript = GameObject.FindObjectOfType<PickUpController>();
}
void Update()
{
if(gameOn == true)
{
if (Input.GetMouseButtonDown(0))
{
// Create a ray from the camera through the mouse pointer in Visual Studio, ScreenPointToRay is shown as incorrect and unity sends // the error below
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
Button hitButton = hitInfo.collider.GetComponent<Button>();
if (hitButton != null)
{
hitButton.onClick.Invoke();
}
}
}
}
}
}
'Camera' does not contain a definition for 'ScreenPointToRay' and no accessible extension method 'ScreenPointToRay' accepting a first argument of type 'Camera' could be found (are you missing a using directive or an assembly reference?)
I want to send out a ray cast through the mouse pointer in 3D.
you created your own class called Camera so it is trying to use that, you need to either put that class into a namespace so that unity doesn't get them confused or just use a different name for that class
Looks like you created your own script named "Camera" and ... yes what Box said
thx boxfriend and PraetorBlue
Hello, I am continuing my puzzle game of triangles. I have an empty object with a script on it that creates a group of triangles. each grouping creates a random amount of triangles, 1 to 6. When certain groups of triangles are created, they aren't centered, and I don't know how to center them
for example the grouping on the right is not centered, and I tried using the bounds of each triangle to determine a min and max x and y and tried to place them according to the min and max x and y, but it's not working
are your triangles sharing points?
they are separate objects
I'm trying to get the average of their sprite renderer bounds, and that's not working
Hey,
So I'm new to the broader C#/.NET ecosystem and I'm surprised to find that the popular cache implementations all seem to store the objects internally as non-generic Ojbects. While Unity doesn't seem to provide it's own cache implementation.
- Wouldn't for example using Microsoft's MemoryCache cause a painful performance penalty for this very reason (due to constant wrapping)?
- Is there a cache implementation that is somewhat "favored" among Unity developers?
- I ofc am not supposed to write my own, am I? ๐ (unfortunately I need a time based eviction policy)
I don't think there's much call for something like a generic LRU or other eviction-based cache in game development.
There is widespread use of object pooling and Unity does provide a canonical implementation of that: https://docs.unity3d.com/ScriptReference/Pool.ObjectPool_1.html
What's your use case?
I'm doing a metric @#$!-ton of raycasts to draw a world grid (inside different floors of buildings as well) that moves in a radius around the player.
Also i don't think we have access to MemoryCache? or am i wrong does mono have it? Ah framework has it, but not standard
something like Death Stranding's scanner?
Also yes a lot of .NET stuff isn't really suitable for game development because it allocates too much garbage
Haven't played it, but judging on the screenshot - something like that, yes.
That's exactly what I'm trying to avoid ๐
You should consider using either:
- a decal projector
- VFX graph with baked SDF for your terrain/surface meshes
Hard to say because I'm not sure exactly what the visual effect you're looking for is
This is the moment I should mention I'm working on a mod, and not sure all options are therefore viable to me.
I already achieved the "visual effect", can screenshot. The problem is now making the solution performant ๐
what's the cache for, raycast results?
Are you sure it's worth caching them? If you use RaycastCommand/Job System you can do quite a few raycasts per frame without an issue
No, in fact I'm not certain.
I'm also considering the Job System (or a combination of that with the cache).
first step should be profiling, assuming you haven't already
Already fixed the obvious bottlenecks from the profiler.
Still doing erm... up to 8k casts per frame.
Is there a reason this is not done in a shader?
Presumably lack of access to physics information in the shader I'd guess?
I see this is a Valheim mod :p
Rendering is breezy. The slow part are firstly the casts themselves and secondly - the logic that processes them.
Is the geometry not okay, the physics colliders are required?
You are correct ๐
https://www.nexusmods.com/valheim/mods/2087
Sounds like a perfect candidate for the job system, or a shader if possible. I have no idea what you actually want/need
You definitely should be using RaycastCommand if you are doing this though
I think both of you are correct yes.
The processing after the raycasts could potentially be jobified as well, depending on what it is.
I was hoping I'm going to be able to make the performance "good enough" as is with a cache slapped on top in the next release. And then improve it via the job system in the next-next release.
It's actually mostly trying to figure out whether I need to do ANOTHER raycast to figure out where the floor is from the perspective of the player.
So at different X and Z coordinates you will need to execute a different number of raycasts.
It's not always say "two hits per tile" (that's actually the best case scenario.
Does this sound like something that the Job System should handle well?
I'm not really sure I follow what these raycasts are doing tbh
or what a "tile" is in this context
Sure.
I can provide sufficient context ๐
This functionality visualizes the world grid as is. So (0, 0) will be an intersection point of the render lines so will (1, 0) and so on. I by definition know all the x, and z coordinates around the player (basically all full integer coordinates around the player in an 8m radius).
The difficult bits is the height.
Altitude. Whatever ๐
When you stand on the roof - the grid needs to be imposed over it.
When you stand on the second floor - it needs to be imposed over the second floor (but respectful of tables, and other pieces that are on top of the floor on which you can put items on).
So I'm basically firing a raycast from the sky diagonal to the ground and drilling through these layers trying to figure out what constitutes as the floor from the players perspective.
And I'm doing that for every intersection point ("tile" as I called it previously) in the radius of the player.
definitely doable in the job system, and much faster too
I imagined I'm going to have to group the raycasts in stages and queue them up in the job system. So in the first wave I would have say 1k raycasts, so in the second, then say 500 in the third, and then a long tale. Where my existing code would need to become aware of these waves and glue them together.
why the waves/stages?
If this interpretation is correct - that sounds as it should be much more efficient than my current sequential approach, but also much more difficult to write (hence why I intended to postpone this to a future release).
Imagine you're on the 0th floor of a 2 story building. I'm casting a ray from space (first wave) and I hit the roof. Okay so we have our first potential "floor". But can we do better? I do another raycast from the previous position. If that hits - we have another potential floor. Now to oversimplify a bit - I'm checking which of these is closer to the player. If it turns out the previous "floor" is closer - no point drilling further - since next levels will only be further away. And we repeat in a loop (next waves) until either that happens (next cast further away than the previous) or until we hit "terrain" layer.
For different X and Z coordinates there might be a different number of casts required (in fact I guarantee it). Sometimes there will be a roof with no floors underneath it. Sometimes there will be furniture inbetween. And such.
So.
The best case scenario from my perspective is if I were able to wrap this whole logic per every "tile" as a single command.
why cast it from space? Why not cast it from the player's position (or slightly above)?
I was considering it. But I don't know what "slightly above" really means unfortunately. It is easly conceivable in Valheim the next floor is ~2m above or 20 meters.
So I kinda have to overshot by definition.
Isn't the player's foot + 1cm sufficient?
Lemme fetch a simple screenshot.
Anyway to start with I'd probaby just hardcode something like 5-10 batches and schedule them all. You might be surprised at how fast the job system is going to be here
The job system lets you schedule a job depending on the results of another job. You can schedule the whole process with a set number of iterations from the get-go
Again - sounds terrifically performant and terrifyingly difficult to implement this logic in "batches" (if I'm not getting the wrong impression of the job system - which I very probably am).
Does anyone know a method for checking if a line goes through a rectangular prism? The prism would be aligned by the 3 global axes, with the minx, miny, minz, maxx and so on
Nah it'd be quite simple. Something like:
NativeArray<RaycastHit> results = new (...);
JobHandle handle = default;
for (int i = 0; i < batchCount;i++) {
MyRaycastJob job = new();
handle = job.schedule(results, 32, 1, handle);
}
handle.Complete();
// your results are now in the results array```
You might have to interleave these jobs with RaycastCommand jobs but that doesn't increase the complexity all that much
just another couple of lines in that loop
Well it does seem like the way to go... Any reading material on the Job System that you would recommend to get me going?
hmmm good question... trying to remember how I learned to use it ๐คฃ
Definitely start with https://docs.unity3d.com/Manual/JobSystem.html
Ok. Thanks Man. Worst case scenario I'll blame it all on you, when my source code inevitably crashes and burns ๐
The suffering of game design
Ahoi, I have an abstract class that implements this method:
public virtual void SetParentGrid(BaseGrid parentGrid)
{
ParentGrid = parentGrid;
}
I want to override this in a derived class with a more specific type of grid that is derived from BaseGrid.
public override void SetParentGrid(HorizontalGrid parentGrid)
{
base.SetParentGrid(parentGrid);
}
Compiler Error CS0115: no suitable method found to override
I guess the compiler doesn't know on its own that BaseGrid is substitutable with HorizontalGrid. Was wondering if there's a type safe way to define this.
Hiya! Have a question on the UI Toolkit, might just need some clarification on how it works. I'm following this UI Example from Unity: https://docs.unity3d.com/Manual/UIE-HowTo-CreateRuntimeUI.html. In the example, Unity has a MainView.cs script that sets up the List Controller during the OnEnable callback. I want to set up the List Controller later on, after OnEnable, from a keystroke or item selection.
However, it seems that the input keystroke or item selection must occur 2x for Unity to actually create the list items - it sets up the ListController and runs the ExecuteCharacterList methods, but no list items are populated until the second trigger. Any ideas why this could be case?
Here's a paste of the updated MainView.cs class. Everything else from the example is unchanged.
https://gdl.space/ahezufevet.cs
Ok silly quaternion question. If I want to do the equivalent of InverseTransformDirection but with only a Quaternion instead of a Transform. Basically "If an object's rotation was this Quaternion, what would be the local direction corresponding to the input world direction? Would this be correct?
public static Vector3 InverseTransformDirection(Quaternion rot, Vector3 inWorldDir) {
Quaternion inv = Quaternion.Inverse(rot);
return inv * inWorldDir;
}```
public void SetParentGrid(HorizontalGrid parentGrid)
{
base.SetParentGrid(parentGrid);
}```
don't override
just make a new overload
but really
there's no point to this
what's the point to this
the point is to not do a runtime check, but do it at compile time
class GridHandler<T> where T : BaseGrid {
T ParentGrid;
public void SetParentGrid(T parentGrid)
{
ParentGrid = parentGrid;
}
}
class HorizontalGridHandler : GridHandler<HorizontalGrid> {
}```
is this what you want?
might be better to ask in #๐งฐโui-toolkit
yes, was thinking about generics aswell, do you know if the compiler is able to actually check if these classes are substitutable?
yep of course
that's what the generic type constraint is for: where T : BaseGrid
nice, thanks
I try to install MLAgent and I'm now to the step of installing the torch program, do anyone know which version of torch is supported right now. Because I couldn't find any information in the docs
doesn't it say here? https://github.com/Unity-Technologies/ml-agents/blob/develop/docs/Installation.md#windows-installing-pytorch
pip3 install torch~=1.7.1
why does fps change depending on what I have selected in the Scene? It ranges from 200 to 1k
drawing the inspector takes time
oh
more or less for different inspectors
aight, makes sense. ty
I am bad at quaternions, but I think you can use fromtorotation with identity as the to argument
That's how I've done it in the past
May be the same as inverse
That kinda sounds like the same as inverse, yeah. Also FromToRotation takes V3 inputs and therefore doesn't really account for roll
how can i turn a vector 2 into an angle to rotate an object by? i want to use the vector 2 movement of my player to turn into an angle for my particles to go the opposite direction in
thanks for the idea though
It was an ancient memory haha
there's no need to calculate an angle
particles.right = -moveDirection;
oh thank you
Hey, I'm working on a project that requires a lot of scripting per level, stuff like: "enemies from this spawner killed -> open door and resume auto scrolling.", "player entered this zone -> spawn enemies", "room entered -> augment camera behavior while inside.", etc. These things are simple enough to implement on their own, but before I waste more time, I want to know what I can do to minimize fiddling and room for error in the inspector, as I will be wiring up a lot of events. I am especially worried about the need to change trigger setups and breaking things across the game, which I have done at least a couple times already.
I started with something like this https://youtu.be/bMuTsAma4tk where I have abstract Trigger and Action classes. This works alright, but it has some shortcomings when I want to "toggle" an action. And I would love to replace inheritance with interfaces, but unity doesn't really support that. And Unity events take a lot of clicks to edit, so I'm not keen on them right now.
This is a bit of a ramble as I'm organizing my thoughts. I haven't decided if a better core approach exists, or if I only need to refine what I have. But does anyone have thoughts on this open-ended generic action/trigger problem? What have you done to tackle it for yourself?
Think less inheritance and interfaces
More modular reusable components
Take Unity's EventTrigger component as an example.
It's an alternative to implementing the event interfaces in your script
Instead of making your script implement an interface, you just throw an EventTrigger down and hook up the events in the inspector
This is easily doable with a moderate understanding of UnityEvent
You can use C# events instead of UnityEvent too
You just have to subscribe in code that's all
how do i enable emission of a particle system in code?
Yes, that should be the right way to do it.
Quaterion.Inverse should work, does it not?
I agree on your points. This is largely how the best iteration of the system works, but I didn't think to separate the event trigger out to be its own component. That sounds promising. Inheritance was the primary issue I had with the system and that should solve it.
It probably does I just didn't feel like setting something up to test it
Yeah looks correct for me
myParticleSystem.Play() right?
I always forget what order to use when transforming world rotation to local, but in this case, there's nothing else you can use Inverse with and that's the only order you can multiply a Vector3 and a Quaternion, so...
this is how i did it, idk if there is a better way
Should be Q * inverse(Q) == inverse(Q) * Q == identity
That's fine if you only want to turn on emission module
Nvm on my system being the same. I had to reread your response. This is pretty different to what I have.
I have a small doubt. So I want to take the transform of an object and update it by making adding a value to the z coordinte. What is the c# code for that?
Does anyone know how to fix the issue Unity won't save my preference for External Script editor and I have to manually select it every time I open my project.
Ah thanks! I didn't see the channel before ๐
transform.position += Vector3.forward * amount;```
or
transform.Translate(0, 0, amount, Space.World);``` (or Space.Local if that's what you want)
Ok thx
I will try it
how do i make the particles relative to the world instead of the player? the way the emission wroks looks very un natural
this looks quite unnatural
it's a checkbox on the particle system
whats it called? sorry im new to making particle
i found it never mind
thank you
adjust simulation space? Oh you did
Seems to work well with some modifications
public abstract class Entity {
public BaseGrid ParentGrid { get; private set; }
public void SetParentGrid<T>(T parentGrid) where T : BaseGrid
{
ParentGrid = parentGrid;
}
}
public class Wall : Entity {
public new void SetParentGrid<T>(T parentGrid) where T : HorizontalGrid
{
base.SetParentGrid(parentGrid);
}
}
public class Structure : Entity { }
Structure structure = new();
Wall wall = new();
HorizontalGrid hGrid = new HorizontalGrid();
VerticalGrid vGrid = new VerticalGrid();
structure.SetParentGrid(hGrid); // Good
structure.SetParentGrid(vGrid); // Good
wall.SetParentGrid(hGrid); // Good
wall.SetParentGrid(vGrid); // Throws an error at compile time just like I wanted
Maybe the context makes somewhat more sense now. Anyways, thanks again. You helped me out a few times now @leaden ice ๐
yeah i did it, thank you :)
i have a floppy bird and i want my powerup to always appear right between two pipes, how can i do that
same way you get the pipes to spawn near each other basically, no?
i have them spawned on timer, i dont suppose that would work unless id somehow time it perfectly
I'm trying to install torch for MLAgent, but when I typed the command:
https://download.pytorch.org/whl/torch_stable.html
I get this:
ERROR: Could not find a version that satisfies the requirement torch==1.7.1 (from versions: none)
ERROR: No matching distribution found for torch==1.7.1```
But in every docs I have seen, none of them talk about this issue, did anyone had the same?
Just spawn them half way through the pipe interval. Use fixed update for spawning so that frame rate won't affect the distance
alright
Computers can manage a much finer grain timing than humans can notice; if youโre off a pixel one way or another, humans almost never can notice anyway.
thats a fair point
also i failed miserably with that pipe ill deal with it later lmao
Does anyone know how to program a randomly generated dungeon
Or should i just use an asset?
oh also i have random spawn on that so im not sure how to do that
random spawns for powerups ofc
Sorry; I hope it works out with a re-view later on.
Anyone know why I'm getting this error, even though my Action's parameters match up with my functions parameters?
show the line with the error
So I had a LOT of fun using maze generation algorithms to build a dungeon, but it's a very specific kind (all hallways, no rooms). If you're looking for something more similar to Rogue, then there's a lot of good algorithms out there, but I always found them a bit frustrating to translate.
better yet - show the whole script
what should I use to upload it
make sure you saved changes too
since Ima have to send 2 whole scripts
Ok luckily I found a tutorial on Brackeyโs channel
For a more general take, there's this: https://github.com/marukrap/RoguelikeDevResources#procedural-map-generation which is...pretty comprehensive. ๐
I really love procedural generation (I own all the related assets from the asset store) even though I know it's a crutch on game design. It's just too much fun.
I've been having this issue where a tilemap that I've made doesn't apply the Tilemap collider to it, despite having it exist on the object. It showed up randomly a couple of days ago, but doesn't anymore for seemingly no reason. Is this something to do with versions of Unity, or something else?
Additionally, any project I make/open with tilemap colliders doesn't actually apply the colliders to them either
can someone help me understand why i get this error
UnassignedReferenceException: The variable UseItem of Selection has not been assigned.
You probably need to assign the UseItem variable of the Selection script in the inspector.
using UnityEngine;
using UnityEngine.UI;
public class Selection : MonoBehaviour
{
public ItemInformation Item;
//Create to reference later
Text Name;
Text Description;
Text Amount;
public GameObject UseItem;
// Start is called before the first frame update
void Start()
{
Name = GameObject.Find("Name").GetComponent<UnityEngine.UI.Text>();
Description = GameObject.Find("Description").GetComponent<UnityEngine.UI.Text>();
// Find the "Amount" GameObject from the scene and use its Text Component.
Amount = GameObject.Find("Amount").GetComponent<UnityEngine.UI.Text>();
Name.enabled = false;
Description.enabled = false;
Amount.enabled = false;
UseItem.SetActive(false);
}
// Update is called once per frame
void Update()
{
}
void OnMouseDown()
{
if (gameObject.tag == "Item")
{
Name.enabled = true;
Description.enabled = true;
Amount.enabled = true;
UseItem.SetActive(true);
Name.text = Item.ItemName;
Description.text = Item.ItemDescription;
// Change the Amount text box
Amount.text = "x " + Item.HeldAmount.ToString();
}
else
{
Name.enabled = false;
Description.enabled = false;
Amount.enabled = false;
UseItem.SetActive(false);
}
}
}
Okay, what have you tried?
You probably need to assign the UseItem variable of the Selection script in the inspector
sorry hit enter early before i had added the code, The issue is that the SetActive(false) works but it causes issues whenever the SetActive(true) is used. i assume its because the object is inactive
did you actually drag the object into the slot on the inspector?
Yes, object is set in inspector and sorry i meant, that the UseItem.SetActive(true) works without giving an error, but setactive false gives the error.
either you didn't actually drag it in or you have more than one copy of this component in the scene where one (or more) of them do not have the object assigned
Which UseItem.SetActive(false) fails? And yeah, do you have multiple of this script in the scene possibly?
when you get this error in Play mode type t:Selection into the hierarchy search bar and screenshot what it shows
actually i found the culprit thank you.
its a plane object i use as the background to detect the "else" clicks in the OnMouseDown.
anyone good with keywordrecognizer? I am trying to debug and find a solution, but I am at loss. I generate a keyword list at the start of the game and I just debug logged it. Basically you can see here in the first image that he has created a keyword "seven". On the second picture he throws a keywordnotfoundexception. I dont understand why.
https://gdl.space/dajimexito.cpp
I keep on getting this error in my code on the given line 41 (i put the code involved in this error in the link), and I don't know how to fix it. It also tells me that it is "outside of bounds of the array" when it is a list. I make sure to check that the Length of each list is the same, and they are, so idk what to do
which is line 77
oh nevermind, i see you commented it
perkLevelsText[i] is likely giving the error, are you sure it has the same number of elements as perkText
That's...not a lot of the code, really. Are any of the other words recognized?
i didnt want to paste what is in my opinion not influencing the problem
its alot else
anyway. yes other words are recognized
i didnt debug exactly the other words, but i can see in the game that it works and i get "correct" etc
for the math tasks i solve
im using sth like this
its also different every time i restart the game
is there a commonly accepted way to know when a nav mesh agent is at its destination? im getting inconsistent results when i google
bonus points if i can wait on it via a custom yield instruction, but if i can get a boolean for is done, then i can do the rest
You mean a different set of words aren't recognized? (It looks like three, for example, wasn't recognized above.)
yes exactly! that is my experience. I didnt investigate entirely which words, but i had the word "two" not being recognized
what could cause this? its like he is deleting sth fromt he dictionary?
maybe its this: actions[speech.text].Invoke();
Im not exactly sure what I was thinking when i put it in there?
idk what it does tbh. i was following a tutorial and experimenting with my lack of knowledge to make things work the way i want them to
What is your actions an array of?
thats the thing. I didnt implement any actions. Basically i am makign a game where you pick up cubes and get math tasks that you can solve with voice recognition. I looked up on the internet and found a tutorial on "keywordrecognizer". The guy explained it with a cube moving according to actions. But all i neded was that i have a dictionary of words that are just numbers, so that the voice recognition only recognizes numbers and if he does find the number spoken to be the solution you get extra seconds
so i programmed it in the weirdest way possible and it worked for me
but now im just realizing that he occasionally throws these exceptions and you basically say the correct solution but he cant find it in the dictionary of numbers
later on now (the tutorial didnt speak about it), i found in the documents of windows speech also a "dictation" function that basically just listens to all your speaking, but that one doesnt seem to be the better choice either because that one listens rather for sentences
so yea. its a messy programming but it did what its supposed to. its just these exceptions i want to fix
i was thinking of maybe adding the exceptions to the dictionary but i am seeing that you have to create the "keywordrecognizer" dictionary at the start and cant really add to it after? at least thats what im thinking
I'm a little stuck on how i.ToWords() is working. ๐ฎ
oh that is simple. i found a library called "humanizer" and i use their function to translate integers into words
so that i can create a dictionary of strings of numbers that i can use for my voice recognition to compare to
1 = "one"
and if i say "one" i can check that against the dictioanry
I figured, but I find it fascinating that it adds the behavior to int. Anyway, why don't you catch the error, and interrogate keywordRecognizer.Keywords to see if it's in the list?
Not sure about a commonly accepted one. Personally, I just created a function that compares the remaining distance and the AI's stopping distance
i dont know how to. im a beginner in coding. XD @frigid anvil i tried a few things but its always saying it doesnt work in the context and i dont know how to write it down
i started with the try catch but then i dont know where to put it and how to write the try
Do you have full error message for KeyNotFoundException?
What is on the Aufgabe.cs line 329?
actions[speech.text].Invoke();
this i really think. i was starting to change the code lines
i think it was this at the line. i will retry the game hold on
Yeah, that's a fair point. If actions is a dictionary, maybe it doesn't contain an entry for the relevant words.
That's the line of issue, there is no corresponding key in actions
What is Actions? Is it a dictionary collection?
ill probably just do this and if it doesnt satisfy the use case later, ill take another look. thanks!
What datatype is actions @swift python ?
This means that the dictionary list you created doesn't have a key value. You should test it first to make sure the key exist, before executing the call...
Try if( actions.TryGetValue(key, out action) ) action.Invoke();
yea i think that might be the issue, im creatin a dictionary of strings with no "key"
I would avoid using string as a key, instead use enum or some other datatype constraint to avoid potential user mistakes.
In this case, the string is coming from the keyword recognizer, so it's kind of an arbitrary thing... I think what you actually want to do is check that the string is equal to the .ToWords(...) of the answer to the math problem. Or something like that.
yea i just removed the line and i get no exceptions anymroe
exactly thank you
i think so the issue why sometimes you had to say it more times was either the exceptions or the confidence level
now it works okay. thanks a bunch guys!
another short question maybe you can help me figure it out faster. I want to "collect" the math tasks in an array. basically every time i touch a cube i will have one displayed at the top and the others be collected in the right box, every time i touch another cube and i didnt finish answering my last question
how do i make a 4x2 array ?
i want it to look like this [[2+3, 5], [2+0, 2] , ..]
first index is the task and the second is the solution
i want to discard any cube that is touched after the array is full, i dont want an endless array. i think 4x2 is fine
or 2x4
I mean...you could do a Dictionary for that, but you could also create a struct like this:
public struct Pair
{
public string Problem;
public string Answer;
}
and then an array of that, like this:
Pair[] p = new Pair[4];
p[0] = new Pair();
p[0].Problem = "1+2";
p[0].Answer = "3";
ah perfect, thanks a bunch!!!! i will try this out ๐
my head is fuming and i cant think anymore ๐ฆ
how can i delete the first element of the struct and move everyone up? And how can I add to the stack ? I think i can come up with the latter by just doing a bunch of if statements. if [0] not null, if [1] not null, etc. but the first question im not sure
By struct you mean array? (it's an array of structs you have there).
Arrays are generally meant to be fixed size, if you want to add/remove from it, you can switch over to a List<Pair> it has RemoveAt(i) Add() methods
Why don't you use a Stack if you want a Stack
Stack<Pair>
or Queue or List if you want those
because i want a fixed size. I will try and see if i can also make them fixed and use the functions
thanks @safe knoll @leaden ice
Essentially you can just check the Count() (I think) of the object before adding anything to it, and disallowing it if it's 4, with a nice 'You can't take on any more problems!' message.
If size is certain, why not make it a const variable? Give it a rule where the program must only allow 4 element array, or why not create a class that holds 4 unique variable representation?
So you don't have to remind yourself what exactly the data in array[2] is used for?
Also gives you power to grow in class size too!
Or, hear me out . . . use an array . . . ๐
If you have to insert and delete, an array becomes annoying.
That has nothing to do with using the appropriate collection for your use case. You'd do more work managing and checking your Count when adding/removing items from a list . . .
It's not my use case; I was helping them, and they were confused how to use an array for it, so I suggested an alternate option.
Oh, well you responded so that confused me . . .
But it was a joke/jab towards Meta . . .
Hey I would appreciate some help with setting up a navmesh. I'm trying to build a navmesh at runtime using Navmesh Components, but it isn't generating.
This github page (https://github.com/Unity-Technologies/NavMeshComponents) says that Navmesh Components is now a part of the unity AI Navigation package. I've tried importing the package and using that, and also importing this legacy version with no use. I've also followed multiple youtube tutorials (which are always about the legacy version) and they didn't help either. I'm happy to provide any necessary info / screenshots if anyone needs any. Thanks in advance
Unfortunately I've been using A* for so long that I'm not sure how you'd do it 'on the fly' for normal nav meshes. ๐ฆ For A* you set the bounds size and tell it to scan it, and it figures it out on the fly.
What is A*?
I'm generating a navmesh for a procedually generated dungeon with set bounds, so something like that could work
https://arongranberg.com/astar/ The A* Pathfinding Project. It was one of the first assets I bought; there's a free version, but I don't know if it does on-the-fly stuff.
Yeah, that's exactly what I did it for. I was writing maze-generation-algorithms in C# and wanted a character to walk the maze to the treasure.
It works with multiple agents right?
Interesting question; yes, in that I've flooded a zone with robots and had them walk around obstacles using it. They were all the same kind of agent, but different individual actors, so while I'm confident it can handle multiple agents, I've not done it with a variety of different ones all configured differently.
Thanks for the suggestion but $100 is a bit out of my price range currently. I may want to buy it if there is no other option, but first I would like to see if I could get NavMeshComponents to work.
hmm it should just work
maybe start with an example somewhere
I can't find any with the updated package
I have navmeshsurface components attached to each floor object, but when I generate the dungeon again the navmesh doesn't update
If I were to hit bake, then randomlyi generate the dungeon again and play the game, it will keep the same navmesh as when I hit bake
Which causes the agents to move through walls, and create invisible bounds
Well yeah, u need to bake after you generate your dungeon or else its not gonna update
And how do I do that?
...and all the forum threads on this are from like...2015 or earlier. I really don't know... It reads like you can't.
bake during runtime after generation is complete
Yes but what do I do to bake during runtime
I can't manually press bake while the game is in play mode
Have you gone through this: https://learn.unity.com/tutorial/runtime-navmesh-generation ?
I figured; just a shot in the dark.
NavMeshComponents seems to simple to do; just make it so that every object that has a navmeshsurface attached to it generates a navmesh on top of it
But seems like you need some extra steps beyond that
Or the package just doesn't work
wdym it uses the outdated package? Seems like it works fine
I've installed the outdated package before and followed all steps of that tutorial and it still didn't work
Okay, so...you have the navmeshsurfaces for everything, and then you loop over all of the surfaces, and call BuildNavMesh() on each of them, right?
BuildNavMesh() doesn't work in the new package
I think I'll install the outdated one and get back to you
But yes I've done that before
I'll try again just to make sure
Right, I see what you're talking about. In 2023.1 it looks like you would use https://docs.unity3d.com/2023.1/Documentation/ScriptReference/AI.NavMeshBuilder.BuildNavMeshData.html to do it.
I've actually never found this link before
I think that may be the problem
Also, what should I include for the first argument, "Build settings"?
There's a link, but it looks like it's a struct with a ton of public members that you can set to behave how you want.
@frigid anvil Thank you SO much for the help, I finally fixed this issue
The navmesh now works as expected
Nice! With the latest version? I'm poking at it myself with a simple two-floor-tile mesh, and it's almost there...
So im using a bluetooth module to connect an arduino to unity with an asset in the unity store, although I am having trouble reading the data being sent to unity the function that reads messages is
IEnumerator VehicleMovement() {
while (BTHelper.isConnected()) {
if (BTHelper.Read() != "")
Debug.Log(BTHelper.Read());
if (BTHelper.ReadBytes() != null)
Debug.Log(BTHelper.ReadBytes());
yield return null;
}
}
```When I dont have the if statements, and just run the debugs, they are just blank/null (I added the bytes just to see if that was the issue)
@compact verge My code looks like this:
void Start()
{
GameObject baseFloor = new GameObject("floor");
GameObject floor1 = Instantiate(floor, baseFloor.transform);
GameObject floor2 = Instantiate(floor, baseFloor.transform);
floor2.transform.Translate(new Vector3(-10, 0, 0));
List<NavMeshBuildSource> results = new List<NavMeshBuildSource>();
List<NavMeshBuildMarkup> empty = new List<NavMeshBuildMarkup>();
NavMeshBuilder.CollectSources(baseFloor.transform,
LayerMask.GetMask("Default"),
NavMeshCollectGeometry.RenderMeshes,
0,
empty,
results);
NavMeshBuildSettings buildSettings = new NavMeshBuildSettings();
buildSettings.agentRadius = 0.5f;
NavMeshData data = NavMeshBuilder.BuildNavMeshData(buildSettings,
results,
fullBounds(baseFloor.transform),
Vector3.zero, Quaternion.identity);
Debug.Log(data);
NavMesh.AddNavMeshData(data);
}
and it appears to do the right thing. In this case floor is a prefab of a simple plane, the default size. fullBounds reads like this:
private Bounds fullBounds(Transform root)
{
Bounds result = new Bounds();
foreach (Transform t in root.GetComponentsInChildren<Transform>())
{
Renderer r = t.GetComponent<Renderer>();
if (r != null)
{
result.Encapsulate(r.bounds);
}
}
return result;
}
Yes it is with the latest version
This is my code:
Oh I can't send it
I need nitro
:/
If it's too big, use a pastebin or the equivalent. I was mostly curious if it came out roughly the same as what I did.
But I got it from the 4th result here, and modified the code a bit to fit my program better. https://forum.unity.com/threads/navmesh-baking-at-runtime-example.507446/
Yeah, pretty similar. I should try tweaking my old A* code to use the stock navmesh instead, like that, and see if it works. 'Course A* includes stuff like, 'If I put this obstacle here, will there still be a path to the endpoint for an agent?', which is helpful. I'm sure there's a way to do that with the stock stuff, though. tl;dr I rely on assets too much. ๐
Congrats on getting it working!
Thanks :)
Could someone try and help out? Im not sure on what the issue is
Unfortunately, at least for myself, I have no Bluetooth knowledge, so all I could offer is stock debugging practices. I presume it is connected, so that if() passes. You're talking about getting bytes from it, but is there a helper that tells you if there are bytes to be actually read? In other words, are you possibly reading bytes when it's not gotten anything, and so your data comes back empty?
And if that's the case, are you confident it's sending the data you need/expect at all? What other mechanisms do you have to read Bluetooth data from your hardware project, to validate that it's sending stuff in the first place?
@pine coralHook your arduino up to the arduino debugger. Are the bytes coming through?
I connected to the bluetooth device on my phone and verified that data goes to my phone, just I am having issues with getting it to send through unity
I was gonna try to just use serial ports instead of bluetooth, but for some reason, im having alot of issues with getting System.IO.Ports installed and to work
It can send/reiceve data when I verified it through my phone
Yes, im using a unity asset from the asset store to connect to the module directly, it works with sending data easily, just reading it for some reason it is giving me some issues
@pine coralWhen I dont have the if statements, and just run the debugs, they are just blank/null What do you mean by this
what if statements are you removing
...and are you confident your computer is receiving the bytes in the first place. There are so many places this could be failing to get you the data in the first place, that aren't even software... ๐ฆ
That's what I was thinking
The ones that basically checked to see if it was empty, the if (BTHelper.Read() != "") and if (BTHelper.ReadBytes() != null)
You might want to start debugging your computer's actual bluetooth module
Well, it can send the data using the same concept, so im assuming it works, just for reading it, it isn't exactly giving me the direct data
Because it can connect to my computer and I have used it a little bit in the past, just instead of tring to send data, I want to receive it
can you try sending bluetooth data from your phone to your computer? Like audio or something?
not in unity, just in some generic music player
Yea, I sent data from my phone to the arduino ide and it showed up fine, I could send/recieve data that way
I'm not talking about your phone to arduino
I'm talking about phone to computer
There's no point debugging code if your module is bricked
this is the first step
Just because it can send data, doesn't mean it can receive it. Something could be broken inside your module.
@pine coral Okay, so... If I'm reading BTHelper right, you have to give it an OnDataReceived method (and other similar ones). Can you pastebin your code someplace? (And yes, what Burt is saying is critical. Can you get any Bluetooth to talk to your computer, just to make sure your BT module is functional to receive in the first place; it's just eliminating variables.)
I tried using the OnDataRecieved as well, and nothing came through, but im not sure if that was correct, but give me a second to upload my full code then I can also check the bluetooth thing burt mentioned
https://hastebin.com/uqareciloh.csharp
Ignore the using System.IO.Ports for now, I was having issues getting that to work, thats why I went with the bluetooth method because I thought it would be easier
@frigid anvil @void basalt I just checked, I could send a file from my phone to my computer through bluetooth
@pine coralLink to documentation please
Of the asset im using?
yes
Its a pdf, if you are fine with me sending that
is this the asset page?
Yes
I should already be on one
Okay, so what I'm reading of this is that you really want something like:
BTHelper.OnDataReceived += () => {
Debug.Log(BTHelper.Read());
};
But I also want to know if (1) the device is paired, (2) the device is connected...
@pine coralWhat data do you need to send from arduino to computer?
The device is already paired to my computer and it does connect upon running the unity scene
But I could test that
Currently just a string, to get it to work
But what is your end goal
Anyone know how to asynchronously convert a byte array to a texture2d? Loading it pauses the render thread if it's big enough
Basically sending data through a joystick module (and 2 button modules) on the arduino from the arduino, to unity through the bluetooth module
yeah
I would do serial
not bluetooth
serial is pretty native. Bluetooth isn't
I've gotten serial working in C# between computer and arduino. It's not too difficult
I was thinking of serial, but when I tried to set up the System.IO.Ports, it gave me an error when trying to download it and I couldn;t figure it out
You shouldn't need to download anything
I just figure a Debug.Log(...) for each of those states would be useful. It's true, a joystick would be better via serial, and might have fewer failure modes. ๐คฃ
serial is native in C#
I have no idea if this actually works with unity
my tests were not in unity
From the things online about how to do it, I need System.IO.Ports, but I dont have that for some reason
Probably because it's not on .NET 7.0, or at least might not have the Platform Extensions. (It's been a bit; I'm not sure what the latest .NET for Unity is.)
Yeah that would probably be why
Would it hurt if I went on a lower .NET for this?
It wouldn't do anything useful
@pine coralBtw your joystick should work with unity
like why not just plug it into your computer
Well ultimately, its for a scholarship im working on, where they want you to connect arduino to unity so
I would much rather just go through my computer directly
The only issue is, that also needs the System.IO.Port library
I can try and download it and show you my error and see if you can help figure something out
On different forums, it says you just need to set your api compatibility level to 4.x
and then ports will work
Because my original plan was to go for serialport, get that working, and if I had time to go with bluetooth, but its causing to many issues, so atp, I just want to get serialport working, but I have no clue how to get the port library
On unity?
Version control?
Do .net framework
the only other option
then try ports again
it should work this time
It will. You might have to close your IDE, and re-open it once Unity has done all the work of updating it. I just tried that.
Ah yea, its working now
I mean it'd be fun, but not if you've got a scholarship thing riding on it.
Yea
I was gonna go with serialfirst, get that done, and if I have time, try bluetooth
I assume you know how to read bytes into primitives and vice versa?
since you will need that knowledge
I don't fully know about bytes, since the bluetooth also allows for string data to be sent, although I should probably learn that as well
basically most data types in c# are 4 bytes
a byte is 8 bits
c# has the byte type
if you want to turn your bytes into an integer, float, etc you can simply cast
you can also bit shift
you absolutely do not want to work with strings for this
lucky for you, when reading stuff from serial, the data is already in byte form
int _myNewInt = (int)_fourByteArray
Ah alright
I can look into that more, but im gonna get the serial method to work at least for now before doing research and getting side tracked
I have a question in regards to null checks. I understand null propagation/null coalescing bypasses the equality check. However this still implies that if the C# reference itself references null, even if it a UnityEngine.Object, should return true.
You can see here that when rb has never been assigned yet that rb is null is false. How is this possible?
If rb was assigned, then Destroy() was called on rb, the C++ instance would be removed but the "C# handler instance/reference" will remain until all references point to null at which point there is nothing to check anyway.
So quick follow up question, im getting an error in unity saying access is denied, im assuming this means it cant access the serialport I tried to have it connect to?
It's fake null, is you do .Equals(null) it would have the check if its either really null or fake null, as far as I know.
Not really sure why that is. Might even be a #archived-code-advanced question.
It might mean that your computer is trying to read that port somewhere else
Dump out the list of available ports?
The arduino IDE isn't really telling me much tbh, just "COM3" as the port so
yeah
you shouldn't be reading from arduino IDE
and from C# at the same time
that will get you errors
I understand it's fake null as I know the equality operator is overwritten to check if the C++ instance of it exists and then is returned true or false depending on the C++ side of things. However this reference is never assigned so this shouldn't even matter
I try and ask it in #archived-code-advanced
You shouldn't need to have arduino IDE opened at all. Your microcontroller should be running itself
True, having both open might conflict. I was thinking from the C# side of things:
Debug.Log("Available Ports:");
foreach (string s in SerialPort.GetPortNames())
{
Debug.Log(s);
}
Yea I can run that real quick, I closed the ide and it got rid of the error, so it might have fixed it, I just need to adjust my code now for it to read serial
Try assigning it to null first (in the declaration), and see if that changes the behavior.
It should change it. And if it still returns false I will throw my PC out of the window
Yea I think my issue was just having the arduino IDE opened as well, forgot to close it since I was messing with that code earlier
If you want, you can also send data back to the arduino, and hook up a motor to make the joystick vibrate when you're shooting something
that would be fun
Ok good I dont have to throw my PC out of the window
Does this have to do with serialization? 
Yea I could, although it wants me to kinda just control a virtual vehicle using external inputs from an arduino (why, no clue), so I was just using a joystick for basic movements, then buttons for turning but im just getting my code to work now for the buttons and do the rest tomorrow
The weird thing is that when I compile, enter playmode, it returns true false but when I exit playmode and enter it again it's true true. (This is also due to the fact that I have domain reloads turned off, although this should technically only apply to statics but I also have the reload scene disabled and this seems like it is influenced by the serialization side of things)
@pine coralThey didn't want you to have a pedal and steering wheel setup instead?
Hi everyone I wanna know how I can populate a dropdown list with the contents of a folder. Can anyone give me clues to where to start?
Technically, they said make a vehicle in unity, have an external input (controlled by an arduino) then have the arduino talk to unity, so I could have done that, but I was doing it wrong for like 3 weeks and im really short on time to do any of that fancy fun stuff for the scholarship, but its something I could do after just for fun (the way the scholarship was worded was hella weird tbh, me and 3 other of my friends all got confused on specifically what they wanted)
"contents of a folder" being? The filenames of the files in a folder?
Interesting; in a quick test, rb is null returns true for me in Start() so I'm not sure what you're seeing...
like lets say a bunch of images inside the folder and I want it to be populated on a dropdown list
This is the behaviour I was expecting
Something like this? https://answers.unity.com/questions/16433/get-list-of-all-files-in-a-directory.html
Try turning off domain & scene reload, make the same getter I made and then maybe call it in Update like I have here? (https://i.imgur.com/uk9PlzR.png)
void Update() //Just so that a field of the return value from the getter is assigned and called in Update
{
Rb.velocity = Vector3.zero
}```
@void basalt now that I think of it, do you think me changing that .NET Framework may have also been a factor on the Bluetooth not properly reading? I'll stick with serial until I get it fully working, but just curious on your opinion
I asked you if you were using the correct .net runtime and you said yes
Regardless, I still wouldn't use bluetooth
one more failure point for when you're giving your presentation
but its up to you
I mean im still sticking with serial for the presentation, but just for messing around after the fact, might as well see what creative things I can come up with after with the stuff I have
Is anyone familiar with reducing coil whine in the Scene view?
When panning in scene view, my computer starts making a whining sound. Apparently it's likely coil whine
It only occurs inside of Unity
I find that hard to believe
Specifically, only when panning the camera
unity isn't going to make your computer make weird noises
Please let me know if anyone ever has any solutions
no
because there is no solution
other than fixing your hardware
unity can't just magically make your computer make a noise because it wants to
its not possible, and it's dumb to think that
You seem unreasonably negative so I'm going to block you
LMAO
"I dont like the answer you gave me so I'm going to block you"
sounds pretty much right
Pretty sure Unity has perfected motherboard sounds till the point it can make it seem like your fan is making loud noises. Not because the motherboard detects high temperatures due to expensive draw calls but because Unity has a special "PC noise" driver. These are some Unity basics I would expect you to know
We need to get together and do the coil whine rain dance ritual so that unity stops making his computer make coil whine noises

Enough joking around. @vague tundra What Burt said is 99.99% the case. Probably what is happening is that panning in the scene view incurs expensive draw calls that increase the temperature of your hardware. Your motherboard detects this and starts spinning the fans faster
It isn't the fans
this isn't something you fix by switching settings
Sorry I dont know what that is, let me consult wikipedia real quick 
that last comment
not meant to you @harsh niche
meant to the kid who blocked me for giving him advice
Anyway, if someone actually knows, please ping me
LMAO
Well it isn't a coding question, so please take it somewhere else.
And if you are going to look at coil whine from something without a coil, you are going to search a whole long while.
It's likely coming from his GPU
GPUs have issues with coil whine
the fact that it happens during draw calls is also an indicator
It could also come from the inductor coils in his PSU
It could be anything hardware related, but he doesn't want that answer
recommended channel?
you know coil whine isn't really something to worry about, right? it's also not an issue with the software as it is literally the hardware vibrating at a frequency that you just happen to be able to hear. it is not indicative of any issue and can potentially happen at any load on the GPU/other hardware
If my card is under RMA you can be damn sure I'm returning it for coil whine
I think #๐ปโunity-talk where you asked is good. But still, I doubt anyone will give a different answer then we already gave you.
#๐โfind-a-channel if you ever don't know what channel to go to
But in this case what Jackson said yeah
What the actual fuck
You haven't heard? Unity makes your computer make weird noises just because it thinks its funny
apparently theres an option somewhere to turn it off. Sarcasm in case anyone is wondering.
<@&502884371011731486>
Hey whilst we are already derailed anybody know what's going on with what I posted in #archived-code-advanced ? ๐
This derailed very quickly indeed
Guys, what is better for Low end Mobile device ? -
- To have 7 scripts with --- transform.LookAt(camera) --- in Update (30fps) and 1 DrawCalll
VS - 14 DrawCalls and no scripts
spend 2 days on shader. and don't know if it even more performant
Thank you.
?
If the drawcall is drawing a black screen the lookat will probably be more expensive
did you know that you can use the unity profiler to determine the performance impacts of your code?
@craggy totemThere's math happening in transform.LookAt(camera). It's not free.
At this point I don't think it matters and I think you're heavily micro-optimizing
You even said that you couldn't find a difference on PC
1 min i'll show what i meant
You could also profile the game remotely on your android.
Also, saying 1 drawcall doesn't mean much. 10 drawcalls for 10 cubes can be more performant then 1 drawcall, if the 1 drawcall is a whole static lowpoly city. (just an example, don't know if 10 or 2 or 100)
So in my opinion, there is no valid answer to your question, you just need to profile it.
The performance here is about the icons. right?
If that's the case I really think it's a case of this
But if you really want to know what's better, do what Jackson said in his last sentence
(Imo it's probably not worth your time)
Stages = new Dictionary<string, ItemHolder[]>();
when i do this, it will drop whatever dictionary it had and create a new one right? no memory leak
DannyWebbie is writing a whole essay in the meanwhile
Finding a way to limit FPS can help, which you might be able to do through GPU control panel #497872469911404564
@void basalt No need to be ass about it, especially since it's not that unlikely for Unity to be the only software where you really notice it.
Yeah the GC will take care of it
@oblique spokeThe only reason I was an ass is because I gave him solid advice and he acts like an asshole about it
regardless, I'm over it
(Tris also said Burt was right)
Thanks. I got an answer that fixed the problem
(Keep this in mind as well for future questions)
Used it before I posted, thanks(:
I want to await a task that moves a gameobject's transform from point A to point B
is there any nice way of doing this or will i have to conjure up something nasty using Update
How to delete a normal class instance like this? bool is supposed to be SerializeField
@swift falconYou can't delete classes in C#
memory is managed for you
just take the object out of storage containers and stop referencing it
C# will pile up unused objects, and delete them for you
If you TRULY want to deal with unmanaged code and delete objects on demand, I think you can do that in C#, but it's tricky
I see, I dont think Ill need that method anyway soon though
Im fine knowing I dont need to bother these stuff. But if performance will greatly improve, I'll bite it then :>
At that point, just use object pools
@vague tundra
Whatโs happening here is that while in the editor the scene view is capped at 30fps while not panning/updating. But during panning the scene view redraw rate is uncapped. Because of this, often if the scene is โsimpleโ enough (compared to your hardware) the editor fps can spike from 30 to 200/2000 rather easily, this then puts strain on the gpu and in turn can cause coilwhine.
You could argue itโs a Unity problem, or a hardware problem, whoโs at fault isnโt really interesting. As for a fix, what I did was limit the max fps for unity.exe in the Nvidia control panel. Iโve heard that some people are running a custom editor script that limits the fps as well, but I have to experience that.
@delicate flaxHis question was already answered about 10 times now
I think he's good
IDisposable Interface?
Might do something
I suppose yeah
I'm not certain, I don't know how the whole GC system exactly works
But it could be of use if you want more "explicit" removal
@woeful leaf"IDisposable does not 'call' the GC, it just 'marks' an object as destroyable."
ยฏ_(ใ)_/ยฏ
quoting from stackoverflow
It tells the GC it can be picked up though, right?
If it meets the criteria, probably
if you still hold a reference to an object, it's probably not going to destroy that object. If you call that reference it's going to not be good
C# is pretty much idiot proof
The world keeps making better idiots, though...
If you call that reference it's going to not be good
I imagine IDisposable would override that
how i can remove android support in my unity editor?
It's sad that I'd agree with this
The object will still exist after calling IDisposable
for probably a few frames
or more
Probably, yes
I'd think that the next GC cycle or so would pick it up
But it'd not instantly vaporise it, no
Not if the object is sitting in a data container somewhere
ยฏ_(ใ)_/ยฏ
Again, I don't know the GC well enough to traverse this topic that much
Anyone able to help me work this out? (Grid based vehicle physics/general parent coding concept)
Scenario 1: I have a frame with a starting point (parent), any additions I make to it will be children of either the parent or the previous addition. When a break is applied the first segment of the "loose" part will become its own parent. Easy enough to make/code.
Scenario 2. Same idea, except this time the frame connects at two points. I don't know how to go about this as technically any child can be the parent (using a parent/child system anyways).
Scenario 3. Same as 2, this time (assuming 2 has been solved), how would you handle breaks that completely sever the child piece? You'd need to allocate a new parent, but aside from picking one randomly how would you do it?
I'm sure there's an existing solution, but I can't find one. Games that come to mind are Cosmoteer, and Banjo Kazooie: Nuts & Bolts.
Red = original parent, green = frame, blue = break
C# does this for you. GC.Collect() is a thing but you really don't need to manage GC for you
Not a good idea to be calling GC.Collect() whenever. That's a huge recipe for lagspikes
source: I've done it
So what is the exact issue you're running in to?
Have you attempted solutions for it?
Or are you just asking for advice before implementing it
Severed pieces need to become their own entity, which I can do since clearing a child's parent makes it it's own parent inherently. The problem I'm having is when there are multiple connection points, making it really hard to think about when it comes to the examples I gave
I feel like the normal parent/child system won't work here at all. But I don't know of any other methods related to this
Maybe Joints would be something to look into?
I mean...I'd imagine it as a particularly stiff rope. Essentially using linked nodes. There's a part of the rope that is between the break and the parent, and part of the rope that is between the break and the end of the rope. In the second case, nothing actually changes, because the parent is still the parent of both sides. The other two cases have a breakpoint that's clear, and anything on that side could become the parent.
If you have hinges at the corners, then scenario 2 just disconnects the two sides, and the rest of the hinges swing freely. But if there aren't hinges, the 'break' doesn't actually...do anything, afaict.
Isn't that assuming that every frame piece is a child of the red circle?
Ya
Gah this is hard to explain. I think what I'm asking is: how do you make each piece know what it's directly connected to?
So the orange would all be children of the red
I'd see it as a FixedJoint; there's a parent/child relationship with the circle, potentially, but they also have an interrelated link between the individual joints and hinges, potentially. It's complicated, and I'd have to play with it, but I think the problem is solvable using Unity's Joint mechanisms.
^
So I am using the Oculus Integration SDK. I need to lock the position of the camera as I am using a 360 video, so I have unchecked the Use position tracking on OVR manager which works perfectly, however, the root position of the controllers is still moving based on the movement of my head, any ideas how to lock the root position of the controllers?
Hey, how should I go about making a value type a reference type? I want to change one color32 and that several sprite renderer change their color to that color32.
Joints look useful for the actual physics, but not the (I'm just going to call them connections from now on) connections part. I've just had an idea though, one sec
You can't do that
You will need to wrap it in a class
Or your sprite renderers need to subscribe to an event
So you trigger that and give the new color
You otherwise can't reference a value type in your case
You could wrap it in a property; it won't do precisely what you're asking for, but it would provide some of the features you might want, I think?
If Unity is smart enough to get the value from the property again, then that works too
Yeah I know that I wouldn't change the type itself, I was looking for some workaround
Not sure if Unity has change tracking like that
I would advice using an event though
Thanks, I was thinking initially about using a class, how would that work exactly? like rend.color = myClass.color?
Since the class is a reference type, the color would change if I change the one from the class, is that correct?
I think so
What I did when I was still a VR dev, was just making the cube-sphere that's playing the video a child of the VR camera.
Don't know if much has changed since then.
You can ask in #๐ฅฝโvirtual-reality for more specific answers.
This is the part that's confusing me; if you need a color to be consistent, read it from a consistent place whenever you use it. Whether that's a Configuration class, or something else, this shouldn't be a problem, and so I'm not sure what's being solved for here.
that won't work for me, i have locked the camera position but need the controllers not be affected by the position of my head movement
Well then I don't know, I suggest asking in #๐ฅฝโvirtual-reality.
ok, thx
Makes sense, I probably don't undestand my problem enough
I'll think about it, thanks for the info ๐
(forgive my crude paint drawings)
-Each piece will have a list of connections.
-When a piece is added, add a connection between it and the piece it's being attached to.
-Since it's grid-based, check the remaining sides for valid connections to other parts. If any add to connections.
-When a break occurs, check the all the removed part's connections independently and all their connections. If there's more than one distinct group, separate them and designate a new parent from the initial connections.
I think this will work, but coding the grid part might be irritating when it comes to multi-block parts :S
Is that a Factorio conveyor belt problem?
I was curious thinking about how it works
Also your paint skills are sick
Basically, I have floating belts that will fall if broken. The issue I'm having is when they have multiple connection points
But this will extend to vehicles as well so I want to do it properly
Forgive me if I'm mistaken cos I didn't read everything, but in Factorio the belts have a direction, do you have that?
So it's scaffolding from minecraft
I've not played MC in years, don't remember scaffold?
The actual belt part has a thin collider, any object touching it will move in a predetermined direction
I meant that when you construct it, you give it a direction
Oh yea that's just a simple rotation, same as Factorio
Cos the way I'd do it, is that each belts have a direction, if there's another belt in that direction, and that belts direction is the same (or 90ยฐ for turns), the object on it can go to the second belt. I'm not sure using physics is necessary at all.
Then each belts have a vector of items which are initially empty, and when stuff gets on it, you put it the item to the last place in the vector, and each frame*objectPerSec you move it to the n-1.
Just a thought tho you do you
I'll keep that in mind, thank you
Hi, Im currently instantiating a prefab:
GameObject FireBall = Instantiate(fireball, transform.position, Quaternion.identity);
Im then trying to remove that FireBall in a script on that fireball after it explodes.
Destroy(gameObject);
This does not work. I have researched about it and have found that you need to be destroying the instance of the PreFab, but im not to sure on how to do this, especially as the destroying is handled by a separate script to the one instantiating it.
I think you would need to be destroying FireBall (the instantiated one)
Destroy(FireBall);
But i cannot do this from the fireball script
Im then trying to remove that FireBall in a script on that fireball after it explodes.
Destroy(gameObject);
This would be the correct way. So we'll need to see your code to see why its failing
Have you debugged and checked that destroy line is running when it should?
sorry i didnt use the reply, so i'll ping just in case you arent looking here @terse venture
yep everything else is running
its just that final line of it being destoyed
no console errors?
if not then it's very strange if that debug.log is firing but the destroy isnt happening
nope
Yep. Ive searched it up and ive read about how it could be trying to destroy the PreFab, but that wouldnt make any sense in my case
why exactly do you need a parent at all?
It should just work.
it wouldnt do that unless you've stored the prefab in your own variable called gameobject
exactly, which i havent
so thats not the issue
this also didnt work
just tried that ahaha
IM SO CONFUSED
I don't think I do explicitly need one, but I do need a way to reference the section(s) as a whole (belt.Reverse() for example)